Skip to content

Commit e749452

Browse files
committed
fix v-repeat reuse vm insertion when detached by v-if
1 parent 393a4e2 commit e749452

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/directives/repeat.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ module.exports = {
233233
var ctn = this.container,
234234
vms = this.vms,
235235
col = this.collection,
236-
el, i, ref, item, primitive, noInsert
236+
el, i, ref, item, primitive, detached
237237

238238
// append node into DOM first
239239
// so v-if can get access to parentNode
@@ -253,7 +253,7 @@ module.exports = {
253253
data.$index = index
254254
// existing VM's el can possibly be detached by v-if.
255255
// in that case don't insert.
256-
noInsert = !el.parentNode
256+
detached = !el.parentNode
257257

258258
} else { // new data, need to create new VM
259259

@@ -275,11 +275,15 @@ module.exports = {
275275
: this.ref
276276
// make sure it works with v-if
277277
if (!ref.parentNode) ref = ref.vue_ref
278-
// insert node with transition
279-
if (!noInsert) {
278+
if (!detached) {
279+
// insert node with transition
280280
transition(el, 1, function () {
281281
ctn.insertBefore(el, ref)
282282
}, this.compiler)
283+
} else {
284+
// detached by v-if
285+
// just move the comment ref node
286+
ctn.insertBefore(el.vue_ref, ref)
283287
}
284288
}
285289

0 commit comments

Comments
 (0)