10000 fallback for slot with v-if should be compiled in child scope (fix #2… · MicroTransactionsMatterToo/vue@9aef0f7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9aef0f7

Browse files
committed
fallback for slot with v-if should be compiled in child scope (fix vuejs#2348)
1 parent 35e5a26 commit 9aef0f7

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

src/directives/element/slot.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ export const slot = {
7373
const elseBlock = document.createElement('template')
7474
elseBlock.setAttribute('v-else', '')
7575
elseBlock.innerHTML = this.el.innerHTML
76+
// the else block should be compiled in child scope
77+
elseBlock._context = this.vm
7678
content.appendChild(elseBlock)
7779
}
7880
const scope = host

src/directives/public/if.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default {
1919
var next = el.nextElementSibling
2020
if (next && getAttr(next, 'v-else') !== null) {
2121
remove(next)
22-
this.elseFactory = new FragmentFactory(this.vm, next)
22+
this.elseFactory = new FragmentFactory(next._context || this.vm, next)
2323
}
2424
// check main block
2525
this.anchor = createAnchor('v-if')

test/unit/specs/directives/element/slot_spec.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,12 +401,16 @@ describe('Slot Distribution', function () {
401401
var vm = new Vue({
402402
el: el,
403403
data: {
404-
ok: false
404+
ok: false,
405+
msg: 'inserted'
405406
},
406-
template: '<div><comp><div v-if="ok">inserted</div></comp></div>',
407+
template: '<div><comp><div v-if="ok">{{ msg }}</div></comp></div>',
407408
components: {
408409
comp: {
409-
template: '<div><slot>fallback</slot></div>'
410+
data: function () {
411+
return { msg: 'fallback' }
412+
},
413+
template: '<div><slot>{{ msg }}</slot></div>'
410414
}
411415
}
412416
})

0 commit comments

Comments
 (0)
0