Browse Source

fix inline-template + v-repeat + <template> (#824)

Evan You 11 years ago
parent
commit
224d53f94d
2 changed files with 28 additions and 2 deletions
  1. 7 0
      src/util/dom.js
  2. 21 2
      test/unit/specs/directives/repeat_spec.js

+ 7 - 0
src/util/dom.js

@@ -195,6 +195,13 @@ exports.removeClass = function (el, cls) {
 exports.extractContent = function (el, asFragment) {
   var child
   var rawContent
+  /* istanbul ignore if */
+  if (
+    el.tagName === 'TEMPLATE' &&
+    el.content instanceof DocumentFragment
+  ) {
+    el = el.content
+  }
   if (el.hasChildNodes()) {
     rawContent = asFragment
       ? document.createDocumentFragment()

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

@@ -172,6 +172,23 @@ if (_.inBrowser) {
       assertMutations(vm, el, done)
     })
 
+    it('v-component with inline-template on <template>', function (done) {
+      var vm = new Vue({
+        el: el,
+        data: {
+          items: [{a:1}, {a:2}]
+        },
+        template:
+          '<template v-repeat="items" v-component="test" inline-template>' +
+            '<div>{{$index}} {{a}}</div>' +
+          '</template>',
+        components: {
+          test: {}
+        }
+      })
+      assertMutations(vm, el, done, true)
+    })
+
     it('v-component with primitive values', function (done) {
       var vm = new Vue({
         el: el,
@@ -774,7 +791,7 @@ function go (fn, cb) {
  * an Array of Objects
  */
 
-function assertMutations (vm, el, done) {
+function assertMutations (vm, el, done, isBlock) {
   assertMarkup()
   var poppedItem
   go(
@@ -832,7 +849,9 @@ function assertMutations (vm, el, done) {
 
   function assertMarkup () {
     var markup = vm.items.map(function (item, i) {
-      return '<div>' + i + ' ' + item.a + '</div>'
+      var el = '<div>' + i + ' ' + item.a + '</div>'
+      if (isBlock) el = '<!--v-start-->' + el + '<!--v-end-->'
+      return el
     }).join('')
     expect(el.innerHTML).toBe(markup + '<!--v-repeat-->')
   }