Преглед изворни кода

transclusion host should be passed at link time,
not compile time. (fix #1185 properly)

Evan You пре 10 година
родитељ
комит
f85160e2aa
4 измењених фајлова са 7 додато и 15 уклоњено
  1. 1 1
      src/api/lifecycle.js
  2. 3 3
      src/compiler/compile.js
  3. 3 8
      src/directives/if.js
  4. 0 3
      src/instance/init.js

+ 1 - 1
src/api/lifecycle.js

@@ -64,5 +64,5 @@ exports.$destroy = function (remove, deferCleanup) {
  */
 
 exports.$compile = function (el, host) {
-  return compiler.compile(el, this.$options, true, host)(this, el)
+  return compiler.compile(el, this.$options, true)(this, el, host)
 }

+ 3 - 3
src/compiler/compile.js

@@ -27,11 +27,10 @@ var terminalDirectives = [
  * @param {Element|DocumentFragment} el
  * @param {Object} options
  * @param {Boolean} partial
- * @param {Vue} [host] - host vm of transcluded content
  * @return {Function}
  */
 
-exports.compile = function (el, options, partial, host) {
+exports.compile = function (el, options, partial) {
   // link function for the node itself.
   var nodeLinkFn = partial || !options._asComponent
     ? compileNode(el, options)
@@ -51,10 +50,11 @@ exports.compile = function (el, options, partial, host) {
    *
    * @param {Vue} vm
    * @param {Element|DocumentFragment} el
+   * @param {Vue} [host] - host vm of transcluded content
    * @return {Function|undefined}
    */
 
-  return function compositeLinkFn (vm, el) {
+  return function compositeLinkFn (vm, el, host) {
     // cache childNodes before linking parent, fix #657
     var childNodes = _.toArray(el.childNodes)
     // link

+ 3 - 8
src/directives/if.js

@@ -21,18 +21,13 @@ module.exports = {
         this.template.appendChild(templateParser.clone(el))
       }
       // compile the nested partial
-      var cacheId =
-        (this.vm.constructor.cid + '.' || '') +
-        // fix #1185: linker is host-sensitive
-        (this._host ? this._host._uid + '.' : '') +
-        el.outerHTML
+      var cacheId = (this.vm.constructor.cid || '') + el.outerHTML
       this.linker = cache.get(cacheId)
       if (!this.linker) {
         this.linker = compiler.compile(
           this.template,
           this.vm.$options,
-          true, // partial
-          this._host // important
+          true // partial
         )
         cache.put(cacheId, this.linker)
       }
@@ -63,7 +58,7 @@ module.exports = {
 
   link: function (frag, linker) {
     var vm = this.vm
-    this.unlink = linker(vm, frag)
+    this.unlink = linker(vm, frag, this._host /* important */)
     transition.blockAppend(frag, this.end, vm)
     // call attached for all the child components created
     // during the compilation

+ 0 - 3
src/instance/init.js

@@ -1,5 +1,4 @@
 var mergeOptions = require('../util').mergeOptions
-var uid = 0
 
 /**
  * The main init sequence. This is called for every
@@ -26,8 +25,6 @@ exports._init = function (options) {
   this._directives = [] // all directives
   this._childCtors = {} // inherit:true constructors
 
-  this._uid = uid++
-
   // a flag to avoid this being observed
   this._isVue = true