Procházet zdrojové kódy

Fix handling v-if along with v-for on a template tag (#2663)

* Fix handling multiple directives on a template tag

* Use a simpler check
Denis Karabaza před 10 roky
rodič
revize
f28260a580
2 změnil soubory, kde provedl 10 přidání a 1 odebrání
  1. 1 1
      src/fragment/factory.js
  2. 9 0
      test/unit/specs/misc_spec.js

+ 1 - 1
src/fragment/factory.js

@@ -18,7 +18,7 @@ export default function FragmentFactory (vm, el) {
   this.vm = vm
   var template
   var isString = typeof el === 'string'
-  if (isString || isTemplate(el)) {
+  if (isString || isTemplate(el) && !el.hasAttribute('v-if')) {
     template = parseTemplate(el, true)
   } else {
     template = document.createDocumentFragment()

+ 9 - 0
test/unit/specs/misc_spec.js

@@ -537,4 +537,13 @@ describe('Misc', function () {
     })
     expect(vm.$el.querySelector('image-field').namespaceURI).not.toMatch(/svg/)
   })
+
+  // #2657
+  it('template v-for with v-if', function () {
+    var vm = new Vue({
+      el: document.createElement('div'),
+      template: '<div><template v-for="n in 6" v-if="n % 2">{{ n }}</template></div>'
+    })
+    expect(vm.$el.textContent).toBe('135')
+  })
 })