Explorar el Código

fix v-repeat with v-component replace:true

Evan You hace 11 años
padre
commit
988026540d
Se han modificado 2 ficheros con 17 adiciones y 4 borrados
  1. 3 3
      src/directives/repeat.js
  2. 14 1
      test/unit/specs/directives/repeat_spec.js

+ 3 - 3
src/directives/repeat.js

@@ -27,17 +27,17 @@ module.exports = {
     } else {
       this.filters.read.unshift(objToArray)
     }
+    // setup ref node
+    this.ref = document.createComment('v-repeat')
+    _.replace(this.el, this.ref)
     // check other directives that need to be handled
     // at v-repeat level
     this.checkIf()
     this.checkRef()
     this.checkTrackById()
     this.checkComponent()
-    // setup ref node
-    this.ref = document.createComment('v-repeat')
     // cache for primitive value instances
     this.cache = Object.create(null)
-    _.replace(this.el, this.ref)
     // check if this is a block repeat
     if (this.el.tagName === 'TEMPLATE') {
       this.el = templateParser.parse(this.el)

+ 14 - 1
test/unit/specs/directives/repeat_spec.js

@@ -111,7 +111,20 @@ if (_.inBrowser) {
     })
 
     it('v-component', function () {
-      // body...
+      var vm = new Vue({
+        el: el,
+        data: {
+          items: [{a:1}, {a:2}, {a:3}]
+        },
+        template: '<div v-repeat="items" v-component="test"></div>',
+        components: {
+          test: {
+            template: '<p>{{$index}} {{a}}</p>',
+            replace: true
+          }
+        }
+      })
+      expect(el.innerHTML).toBe('<p>0 1</p><p>1 2</p><p>2 3</p><!--v-repeat-->')
     })
 
     it('nested repeats', function () {