Skip to content

Commit

Permalink
fix: new syntax slots without scope should also be exposed on functio…
Browse files Browse the repository at this point in the history
…nal slots()
  • Loading branch information
yyx990803 committed Feb 8, 2019
1 parent 099f3ba commit 8a80086
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/core/vdom/create-functional-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 15 additions & 0 deletions test/unit/features/component/component-scoped-slot.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})

0 comments on commit 8a80086

Please sign in to comment.