Просмотр исходного кода

compile v-if content with correct transclusion host (fix #1097)

Evan You 11 лет назад
Родитель
Сommit
3483db2ced
2 измененных файлов с 30 добавлено и 1 удалено
  1. 2 1
      src/directives/if.js
  2. 28 0
      test/unit/specs/directives/if_spec.js

+ 2 - 1
src/directives/if.js

@@ -27,7 +27,8 @@ module.exports = {
         this.linker = compiler.compile(
           this.template,
           this.vm.$options,
-          true
+          true, // partial
+          this._host // important
         )
         cache.put(cacheId, this.linker)
       }

+ 28 - 0
test/unit/specs/directives/if_spec.js

@@ -327,5 +327,33 @@ if (_.inBrowser) {
       }
     })
 
+    // #1097 v-if components not having correct parent
+    it('compile with correct transclusion host', function () {
+      var parentA
+      var parentB
+      new Vue({
+        el: el,
+        data: {
+          show: true
+        },
+        template: '<parent><child v-if="show"></child></parent>',
+        components: {
+          parent: {
+            template: '<content></content>',
+            created: function () {
+              parentA = this
+            }
+          },
+          child: {
+            created: function () {
+              parentB = this.$parent
+            }
+          }
+        }
+      })
+      expect(parentA).toBeTruthy()
+      expect(parentA).toBe(parentB)
+    })
+
   })
 }