mirror of https://github.com/vuejs/vue.git
Tweak parent directive compilation
- Make `this.el.__vue__` avaialable in a parent directive on the component container. - Move `v-ref` compilation to parent instead of child
This commit is contained in:
parent
cdd1e095b5
commit
bf9edefca0
|
@ -472,7 +472,6 @@ function collectDirectives (el, options, asParent) {
|
||||||
dirName = attrName.slice(config.prefix.length)
|
dirName = attrName.slice(config.prefix.length)
|
||||||
if (asParent &&
|
if (asParent &&
|
||||||
(dirName === 'with' ||
|
(dirName === 'with' ||
|
||||||
dirName === 'ref' ||
|
|
||||||
dirName === 'component')) {
|
dirName === 'component')) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,19 +5,26 @@ module.exports = {
|
||||||
isLiteral: true,
|
isLiteral: true,
|
||||||
|
|
||||||
bind: function () {
|
bind: function () {
|
||||||
if (this.el !== this.vm.$el) {
|
var child = this.el.__vue__
|
||||||
|
if (!child) {
|
||||||
_.warn(
|
_.warn(
|
||||||
'v-ref should only be used on instance root nodes.'
|
'v-ref should only be used on instance root nodes.'
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.owner = this.vm.$parent
|
if (this.vm !== child.$parent) {
|
||||||
this.owner.$[this.expression] = this.vm
|
_.warn(
|
||||||
|
'v-ref should be used from the parent template,' +
|
||||||
|
' not the component\'s.'
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.vm.$[this.expression] = child
|
||||||
},
|
},
|
||||||
|
|
||||||
unbind: function () {
|
unbind: function () {
|
||||||
if (this.owner.$[this.expression] === this.vm) {
|
if (this.vm.$[this.expression] === this.el.__vue__) {
|
||||||
delete this.owner.$[this.expression]
|
delete this.vm.$[this.expression]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,13 +46,14 @@ exports._compile = function (el) {
|
||||||
}
|
}
|
||||||
// tranclude, this possibly replaces original
|
// tranclude, this possibly replaces original
|
||||||
el = transclude(el, options)
|
el = transclude(el, options)
|
||||||
|
this._initElement(el)
|
||||||
// now call the container linker on the resolved el
|
// now call the container linker on the resolved el
|
||||||
this._containerUnlinkFn = containerLinkFn(parent, el)
|
this._containerUnlinkFn = containerLinkFn(parent, el)
|
||||||
} else {
|
} else {
|
||||||
// simply transclude
|
// simply transclude
|
||||||
el = transclude(el, options)
|
el = transclude(el, options)
|
||||||
|
this._initElement(el)
|
||||||
}
|
}
|
||||||
this._initElement(el)
|
|
||||||
var linkFn = compile(el, options)
|
var linkFn = compile(el, options)
|
||||||
linkFn(this, el)
|
linkFn(this, el)
|
||||||
if (options.replace) {
|
if (options.replace) {
|
||||||
|
|
|
@ -204,13 +204,13 @@ if (_.inBrowser) {
|
||||||
expect(vm._bindDir.calls.count()).toBe(0)
|
expect(vm._bindDir.calls.count()).toBe(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('component parent scope compilation should skip v-ref, v-with & v-component', function () {
|
it('component parent scope compilation should skip v-with & v-component', function () {
|
||||||
el.innerHTML = '<div v-component v-ref="test" v-with="test"></div>'
|
el.innerHTML = '<div v-component v-with="test"></div>'
|
||||||
el = el.firstChild
|
el = el.firstChild
|
||||||
var linker = compile(el, Vue.options, true, true)
|
var linker = compile(el, Vue.options, true, true)
|
||||||
linker(vm, el)
|
linker(vm, el)
|
||||||
expect(vm._directives.length).toBe(0)
|
expect(vm._directives.length).toBe(0)
|
||||||
expect(el.attributes.length).toBe(3)
|
expect(el.attributes.length).toBe(2)
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue