Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/fragment/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) && !hasDirectives(el)) {
template = parseTemplate(el, true)
} else {
template = document.createDocumentFragment()
Expand All @@ -41,6 +41,15 @@ export default function FragmentFactory (vm, el) {
this.linker = linker
}

function hasDirectives (el) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be simpler, since v-for and v-if are the only ones that can work on <template>, and v-for has higher priority than v-if, it seems v-if is the only thing that we need to check.

if (!el.hasAttributes()) return false
var i = el.attributes.length
while (i--) {
if (el.attributes[i].name.substring(0, 2) === 'v-') return true
}
return false
}

/**
* Create a fragment instance with given host and scope.
*
Expand Down
9 changes: 9 additions & 0 deletions test/unit/specs/misc_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})