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)
|
||||
if (asParent &&
|
||||
(dirName === 'with' ||
|
||||
dirName === 'ref' ||
|
||||
dirName === 'component')) {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -5,19 +5,26 @@ module.exports = {
|
|||
isLiteral: true,
|
||||
|
||||
bind: function () {
|
||||
if (this.el !== this.vm.$el) {
|
||||
var child = this.el.__vue__
|
||||
if (!child) {
|
||||
_.warn(
|
||||
'v-ref should only be used on instance root nodes.'
|
||||
)
|
||||
return
|
||||
}
|
||||
this.owner = this.vm.$parent
|
||||
this.owner.$[this.expression] = this.vm
|
||||
if (this.vm !== child.$parent) {
|
||||
_.warn(
|
||||
'v-ref should be used from the parent template,' +
|
||||
' not the component\'s.'
|
||||
)
|
||||
return
|
||||
}
|
||||
this.vm.$[this.expression] = child
|
||||
},
|
||||
|
||||
unbind: function () {
|
||||
if (this.owner.$[this.expression] === this.vm) {
|
||||
delete this.owner.$[this.expression]
|
||||
if (this.vm.$[this.expression] === this.el.__vue__) {
|
||||
delete this.vm.$[this.expression]
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -46,13 +46,14 @@ exports._compile = function (el) {
|
|||
}
|
||||
// tranclude, this possibly replaces original
|
||||
el = transclude(el, options)
|
||||
this._initElement(el)
|
||||
// now call the container linker on the resolved el
|
||||
this._containerUnlinkFn = containerLinkFn(parent, el)
|
||||
} else {
|
||||
// simply transclude
|
||||
el = transclude(el, options)
|
||||
this._initElement(el)
|
||||
}
|
||||
this._initElement(el)
|
||||
var linkFn = compile(el, options)
|
||||
linkFn(this, el)
|
||||
if (options.replace) {
|
||||
|
|
|
@ -204,13 +204,13 @@ if (_.inBrowser) {
|
|||
expect(vm._bindDir.calls.count()).toBe(0)
|
||||
})
|
||||
|
||||
it('component parent scope compilation should skip v-ref, v-with & v-component', function () {
|
||||
el.innerHTML = '<div v-component v-ref="test" v-with="test"></div>'
|
||||
it('component parent scope compilation should skip v-with & v-component', function () {
|
||||
el.innerHTML = '<div v-component v-with="test"></div>'
|
||||
el = el.firstChild
|
||||
var linker = compile(el, Vue.options, true, true)
|
||||
linker(vm, el)
|
||||
expect(vm._directives.length).toBe(0)
|
||||
expect(el.attributes.length).toBe(3)
|
||||
expect(el.attributes.length).toBe(2)
|
||||
})
|
||||
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue