Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f28260a

Browse files
simplesmileryyx990803
authored andcommitted
Fix handling v-if along with v-for on a template tag (vuejs#2663)
* Fix handling multiple directives on a template tag * Use a simpler check
1 parent 219b80b commit f28260a

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

‎src/fragment/factory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default function FragmentFactory (vm, el) {
1818
this.vm = vm
1919
var template
2020
var isString = typeof el === 'string'
21-
if (isString || isTemplate(el)) {
21+
if (isString || isTemplate(el) && !el.hasAttribute('v-if')) {
2222
template = parseTemplate(el, true)
2323
} else {
2424
template = document.createDocumentFragment()

‎test/unit/specs/misc_spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,4 +537,13 @@ describe('Misc', function () {
537537
})
538538
expect(vm.$el.querySelector('image-field').namespaceURI).not.toMatch(/svg/)
539539
})
540+
541+
// #2657
542+
it('template v-for with v-if', function () {
543+
var vm = new Vue({
544+
el: document.createElement('div'),
545+
template: '<div><template v-for="n in 6" v-if="n % 2">{{ n }}</template></div>'
546+
})
547+
expect(vm.$el.textContent).toBe('135')
548+
})
540549
})

0 commit comments

Comments
 (0)