Skip to content

Commit 66de1cc

Browse files
committed
update syntax for v-ref & v-el
1 parent 9780be8 commit 66de1cc

File tree

9 files changed

+49
-27
lines changed

9 files changed

+49
-27
lines changed

src/compiler/compile.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ var componentDef = require('../directives/component')
1212
var bindRE = /^:|^v-bind:/
1313
var onRE = /^@/
1414
var argRE = /:(.*)$/
15-
var nodeRefRE = /^\$\$\./
1615

1716
// terminal directives
1817
var terminalDirectives = [
@@ -613,15 +612,6 @@ function compileDirectives (attrs, options) {
613612
})
614613
} else
615614

616-
if (nodeRefRE.test(name)) {
617-
value = _.camelize(name.replace(nodeRefRE, ''))
618-
dirs.push({
619-
name: 'el',
620-
descriptors: [newDirParser.parse(value)],
621-
def: options.directives.el
622-
})
623-
} else
624-
625615
// attribute bindings
626616
if (bindRE.test(name)) {
627617
var attributeName = name.replace(bindRE, '')

src/deprecations.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,17 @@ if (process.env.NODE_ENV !== 'production') {
8383

8484
V_REF: function () {
8585
warn(
86-
'v-ref will no longer be a directive in 1.0.0; Use the "$.id" special ' +
87-
'syntax instead. See https://github.com/yyx990803/vue/issues/1292 for details.'
86+
'v-ref will no longer take an attribute value in 1.0.0. Use "v-ref:id" syntax ' +
87+
'instead. Also, refs will be registered under vm.$refs instead of vm.$.' +
88+
newBindingSyntaxLink
89+
)
90+
},
91+
92+
V_EL: function () {
93+
warn(
94+
'v-el will no longer take an attribute value in 1.0.0. Use "v-el:id" syntax ' +
95+
'instead. Also, nodes will be registered under vm.$els instead of vm.$$.' +
96+
newBindingSyntaxLink
8897
)
8998
},
9099

src/directives/el.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,15 @@ module.exports = {
66
priority: 1500,
77

88
bind: function () {
9+
var id = this.arg
10+
? _.camelize(this.arg)
11+
: this.expression
12+
if (process.env.NODE_ENV !== 'production' &&
13+
!this.arg && id) {
14+
_.deprecation.V_EL()
15+
}
916
if (!this._isDynamicLiteral) {
10-
this.update(this.expression)
17+
this.update(id)
1118
}
1219
},
1320

src/directives/ref.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports = {
1515
// If we get here, it means this is a `v-ref` on a
1616
// child, because parent scope `v-ref` is stripped in
1717
// `v-component` already.
18-
var ref = this.expression
18+
var ref = this.arg || this.expression
1919
var context = this.vm._scope || this.vm._context
2020
context.$[ref] = this.vm
2121

src/util/dom.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ exports.getBindAttr = function (node, name) {
7979
return val
8080
}
8181

82-
var refRE = /^\$\./
82+
var refRE = /^v-ref:/
8383
exports.findRef = function (node) {
8484
if (node.hasAttributes()) {
8585
var attrs = node.attributes

src/vue.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,22 @@ Object.defineProperty(p, '$data', {
6666
}
6767
})
6868

69+
/**
70+
* 1.0.0-alpha for 0.12 compat
71+
*/
72+
73+
Object.defineProperty(p, '$els', {
74+
get: function () {
75+
return this.$$
76+
}
77+
})
78+
79+
Object.defineProperty(p, '$refs', {
80+
get: function () {
81+
return this.$
82+
}
83+
})
84+
6985
/**
7086
* Mixin internal instance methods
7187
*/

test/unit/specs/directives/el_spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@ if (_.inBrowser) {
4747
data: {
4848
ok: true
4949
},
50-
template: '<div $$.test-el v-if="ok" id="test"></div>'
50+
template: '<div v-el:test-el v-if="ok" id="test"></div>'
5151
})
52-
expect(vm.$$.testEl).toBeTruthy()
53-
expect(vm.$$.testEl.id).toBe('test')
52+
expect(vm.$els.testEl).toBeTruthy()
53+
expect(vm.$els.testEl.id).toBe('test')
5454
vm.ok = false
5555
_.nextTick(function () {
56-
expect(vm.$$.testEl).toBeNull()
56+
expect(vm.$els.testEl).toBeNull()
5757
vm.ok = true
5858
_.nextTick(function () {
59-
expect(vm.$$.testEl.id).toBe('test')
59+
expect(vm.$els.testEl.id).toBe('test')
6060
done()
6161
})
6262
})

test/unit/specs/directives/prop_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ if (_.inBrowser) {
195195
data: {
196196
b: 'B'
197197
},
198-
template: '<test $.child :b*="b"></test>',
198+
template: '<test v-ref:child :b*="b"></test>',
199199
components: {
200200
test: {
201201
props: ['b'],

test/unit/specs/directives/ref_spec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ if (_.inBrowser) {
2626
data: {
2727
ref: 'test2'
2828
},
29-
template: '<test $.test-ref></test><test2 v-ref="{{ref}}"></test2>'
29+
template: '<test v-ref:test-ref></test><test2 v-ref="{{ref}}"></test2>'
3030
})
31-
expect(vm.$.testRef).toBeTruthy()
32-
expect(vm.$.testRef.$options.id).toBe('test')
31+
expect(vm.$refs.testRef).toBeTruthy()
32+
expect(vm.$refs.testRef.$options.id).toBe('test')
3333
expect(vm.$.test2).toBeTruthy()
3434
expect(vm.$.test2.$options.id).toBe('test2')
3535
})
@@ -39,7 +39,7 @@ if (_.inBrowser) {
3939
el: el,
4040
components: components,
4141
data: { test: 'test' },
42-
template: '<component :is="test" $.test></component>'
42+
template: '<component :is="test" v-ref:test></component>'
4343
})
4444
expect(vm.$.test.$options.id).toBe('test')
4545
vm.test = 'test2'
@@ -57,7 +57,7 @@ if (_.inBrowser) {
5757
var vm = new Vue({
5858
el: el,
5959
data: { view: 'one' },
60-
template: '{{$.test.value}}<component :is="view" $.test></component>',
60+
template: '{{$refs.test.value}}<component :is="view" v-ref:test></component>',
6161
components: {
6262
one: {
6363
id: 'one',
@@ -96,7 +96,7 @@ if (_.inBrowser) {
9696
el: el,
9797
template:
9898
'<div>' +
99-
'<comp $.out>{{$.out.msg}}</comp>' +
99+
'<comp v-ref:out>{{$refs.out.msg}}</comp>' +
100100
'</div>',
101101
components: {
102102
comp: {

0 commit comments

Comments
 (0)