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

42 lines
1003 B
TypeScript
Raw Normal View History

2019-10-22 15:26:48 +00:00
import { Data } from '../component'
import { Slots } from '../componentSlots'
import {
VNodeArrayChildren,
openBlock,
createBlock,
Fragment,
VNode
} from '../vnode'
import { PatchFlags } from '@vue/shared'
2020-02-07 06:06:51 +00:00
import { warn } from '../warning'
2019-09-28 00:29:20 +00:00
export function renderSlot(
slots: Slots,
name: string,
2019-10-22 15:26:48 +00:00
props: Data = {},
2019-09-28 00:29:20 +00:00
// this is not a user-facing function, so the fallback is always generated by
2019-10-05 14:48:54 +00:00
// the compiler and guaranteed to be an array
fallback?: VNodeArrayChildren
): VNode {
2020-02-07 06:06:51 +00:00
let slot = slots[name]
if (__DEV__ && slot && slot.length > 1) {
2020-02-07 06:06:51 +00:00
warn(
`SSR-optimized slot function detected in a non-SSR-optimized render ` +
`function. You need to mark this component with $dynamic-slots in the ` +
`parent template.`
)
slot = () => []
}
return (
openBlock(),
createBlock(
Fragment,
{ key: props.key },
slot ? slot(props) : fallback || [],
slots._ ? PatchFlags.STABLE_FRAGMENT : PatchFlags.BAIL
)
)
2019-09-28 00:29:20 +00:00
}