Skip to content

Commit 182fe83

Browse files
author
Evan You
committed
give v-with higest priority among normal directives (fix vuejs#282)
1 parent 108122b commit 182fe83

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

src/compiler.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -523,10 +523,24 @@ CompilerProto.compileElement = function (node, root) {
523523
node.vue_effect = this.eval(utils.attr(node, 'effect'))
524524

525525
var prefix = config.prefix + '-',
526-
attrs = slice.call(node.attributes),
527526
params = this.options.paramAttributes,
528527
attr, attrname, isDirective, exp, directives, directive, dirname
529528

529+
// v-with has special priority among the rest
530+
// it needs to pull in the value from the parent before
531+
// computed properties are evaluated, because at this stage
532+
// the computed properties have not set up their dependencies yet.
533+
if (root) {
534+
var withExp = utils.attr(node, 'with')
535+
if (withExp) {
536+
directives = this.parseDirective('with', withExp, node, true)
537+
for (j = 0, k = directives.length; j < k; j++) {
538+
this.bindDirective(directives[j], this.parent)
539+
}
540+
}
541+
}
542+
543+
var attrs = slice.call(node.attributes)
530544
for (i = 0, l = attrs.length; i < l; i++) {
531545

532546
attr = attrs[i]
@@ -542,12 +556,7 @@ CompilerProto.compileElement = function (node, root) {
542556
// loop through clauses (separated by ",")
543557
// inside each attribute
544558
for (j = 0, k = directives.length; j < k; j++) {
545-
directive = directives[j]
546-
if (dirname === 'with') {
547-
this.bindDirective(directive, this.parent)
548-
} else {
549-
this.bindDirective(directive)
550-
}
559+
this.bindDirective(directives[j])
551560
}
552561
} else if (config.interpolate) {
553562
// non directive attribute, check interpolation tags

test/unit/specs/api.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,14 +680,15 @@ describe('API', function () {
680680
assert.strictEqual(v.$data.c, null)
681681
})
682682

683-
it('should be able in bind data from parents', function (done) {
683+
it('should be able to bind data from parents', function (done) {
684684
var v = new Vue({
685685
template: '<div v-component="test" v-ref="child"></div>',
686686
data: {
687687
size: 123
688688
},
689689
components: {
690690
test: {
691+
replace: true,
691692
paramAttributes: ['size'],
692693
template: '<div class="child" size="{{size}}"></div>'
693694
}

0 commit comments

Comments
 (0)