fix: new syntax slots without scope should also be exposed on functional slots()

This commit is contained in:
Evan You 2019-02-08 14:45:45 -05:00
parent 099f3ba600
commit 8a800867fe
2 changed files with 24 additions and 1 deletions

View File

@ -49,7 +49,15 @@ export function FunctionalRenderContext (
this.parent = parent
this.listeners = data.on || emptyObject
this.injections = resolveInject(options.inject, parent)
this.slots = () => this.$slots || (this.$slots = resolveSlots(children, parent))
this.slots = () => {
if (!this.$slots) {
normalizeScopedSlots(
data.scopedSlots,
this.$slots = resolveSlots(children, parent)
)
}
return this.$slots
}
Object.defineProperty(this, 'scopedSlots', ({
enumerable: true,

View File

@ -1088,4 +1088,19 @@ describe('Component scoped slot', () => {
}).$mount()
expect(vm.$el.textContent).toBe('')
})
it('should expose v-slot without scope on ctx.slots() in functional', () => {
const vm = new Vue({
template: `<foo><template v-slot>hello</template></foo>`,
components: {
foo: {
functional: true,
render(h, ctx) {
return h('div', ctx.slots().default)
}
}
}
}).$mount()
expect(vm.$el.textContent).toBe('hello')
})
})