vue3-yuanma/packages/runtime-core/src/helpers/renderSlot.ts

28 lines
559 B
TypeScript
Raw Normal View History

2019-09-28 00:29:20 +00:00
import { Slot } from '../componentSlots'
import {
VNodeChildren,
openBlock,
createBlock,
Fragment,
VNode
} from '../vnode'
2019-09-28 00:29:20 +00:00
export function renderSlot(
slots: Record<string, Slot>,
key: string,
2019-09-28 00:29:20 +00:00
props: any = {},
// this is not a user-facing function, so the fallback is always generated by
// the compiler and gurunteed to be an array
fallback?: VNodeChildren
): VNode {
const slot = slots[key]
return (
openBlock(),
createBlock(
Fragment,
{ key: props.key },
slot ? slot(props) : fallback || []
)
)
2019-09-28 00:29:20 +00:00
}