mirror of
https://github.com/vuejs/vue.git
synced 2024-11-22 04:39:46 +00:00
fix(setup): ensure setup context slots can be accessed immediately
fix #12672
This commit is contained in:
parent
ea5d0f3fbf
commit
67760f8d30
@ -25,7 +25,13 @@ export function initRender(vm: Component) {
|
||||
const parentVnode = (vm.$vnode = options._parentVnode!) // the placeholder node in parent tree
|
||||
const renderContext = parentVnode && (parentVnode.context as Component)
|
||||
vm.$slots = resolveSlots(options._renderChildren, renderContext)
|
||||
vm.$scopedSlots = emptyObject
|
||||
vm.$scopedSlots = parentVnode
|
||||
? normalizeScopedSlots(
|
||||
vm.$parent!,
|
||||
parentVnode.data!.scopedSlots,
|
||||
vm.$slots
|
||||
)
|
||||
: emptyObject
|
||||
// bind the createElement fn to this instance
|
||||
// so that we get proper render context inside it.
|
||||
// args order: tag, data, children, normalizationType, alwaysNormalize
|
||||
@ -98,7 +104,7 @@ export function renderMixin(Vue: typeof Component) {
|
||||
const vm: Component = this
|
||||
const { render, _parentVnode } = vm.$options
|
||||
|
||||
if (_parentVnode) {
|
||||
if (_parentVnode && vm._isMounted) {
|
||||
vm.$scopedSlots = normalizeScopedSlots(
|
||||
vm.$parent!,
|
||||
_parentVnode.data!.scopedSlots,
|
||||
|
@ -165,6 +165,9 @@ describe('api: setup context', () => {
|
||||
|
||||
const Child = {
|
||||
setup(_props: any, { slots }: any) {
|
||||
// #12672 behavior consistency with Vue 3: should be able to access
|
||||
// slots directly in setup()
|
||||
expect(slots.foo()).toBeTruthy()
|
||||
return () => h('div', [...slots.foo(), ...slots.bar()])
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user