diff --git a/src/compiler/codegen/index.js b/src/compiler/codegen/index.js index a8c7d4d5..17b31e5b 100644 --- a/src/compiler/codegen/index.js +++ b/src/compiler/codegen/index.js @@ -343,11 +343,14 @@ function genScopedSlot ( if (el.for && !el.forProcessed) { return genForScopedSlot(key, el, state) } - return `{key:${key},fn:function(${String(el.slotScope)}){` + + const fn = `function(${String(el.slotScope)}){` + `return ${el.tag === 'template' - ? genChildren(el, state) || 'void 0' + ? el.if + ? `${el.if}?${genChildren(el, state) || 'undefined'}:undefined` + : genChildren(el, state) || 'undefined' : genElement(el, state) - }}}` + }}` + return `{key:${key},fn:${fn}}` } function genForScopedSlot ( diff --git a/test/unit/features/component/component-scoped-slot.spec.js b/test/unit/features/component/component-scoped-slot.spec.js index 8c17befd..4fab0127 100644 --- a/test/unit/features/component/component-scoped-slot.spec.js +++ b/test/unit/features/component/component-scoped-slot.spec.js @@ -557,4 +557,40 @@ describe('Component scoped slot', () => { expect(vm.$el.innerHTML).toBe('world foo world bar world abc') }).then(done) }) + + // #6725 + it('scoped slot with v-if', done => { + const vm = new Vue({ + data: { + ok: false + }, + template: ` + + + + `, + components: { + test: { + data () { + return { msg: 'hello' } + }, + template: ` +
+ + {{ msg }} fallback + +
+ ` + } + } + }).$mount() + expect(vm.$el.innerHTML).toBe('hello fallback') + + vm.ok = true + waitForUpdate(() => { + expect(vm.$el.innerHTML).toBe('

hello

') + }).then(done) + }) })