Explorar o código

fix #822: v-repeat & custom element components

Evan You %!s(int64=11) %!d(string=hai) anos
pai
achega
a38012bf0c
Modificáronse 2 ficheiros con 25 adicións e 0 borrados
  1. 4 0
      src/directives/repeat.js
  2. 21 0
      test/unit/specs/directives/repeat_spec.js

+ 4 - 0
src/directives/repeat.js

@@ -114,6 +114,10 @@ module.exports = {
         merged._asComponent = true
         merged._parent = this.vm
         this.template = transclude(this.template, merged)
+        // Important: mark the template as a root node so that
+        // custom element components don't get compiled twice.
+        // fixes #822
+        this.template.__vue__ = true
         this._linkFn = compile(this.template, merged)
       } else {
         // to be resolved later

+ 21 - 0
test/unit/specs/directives/repeat_spec.js

@@ -210,6 +210,27 @@ if (_.inBrowser) {
     })
 
     it('custom element component', function () {
+      var vm = new Vue({
+        el: el,
+        data: {
+          items: [{a:1}, {a:2}, {a:3}]
+        },
+        template: '<test-component v-repeat="items"></test-component>',
+        components: {
+          'test-component': {
+            template: '{{$index}} {{a}}'
+          }
+        }
+      })
+      expect(el.innerHTML).toBe(
+        '<test-component>0 1</test-component>' +
+        '<test-component>1 2</test-component>' +
+        '<test-component>2 3</test-component>' +
+        '<!--v-repeat-->'
+      )
+    })
+
+    it('custom element component with replace:true', function () {
       var vm = new Vue({
         el: el,
         data: {