Browse Source

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

dev
Evan You 6 years ago
parent
commit
8a800867fe
  1. 10
      src/core/vdom/create-functional-component.js
  2. 15
      test/unit/features/component/component-scoped-slot.spec.js

10
src/core/vdom/create-functional-component.js

@ -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,

15
test/unit/features/component/component-scoped-slot.spec.js

@ -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')
})
})

Loading…
Cancel
Save