| 123456789101112131415161718192021222324 |
- import { ComponentPublicInstance, SetupContext, EmitsOptions } from 'vue';
- /**
- * 获取指定插槽内容
- *
- * @param param0 组件实例instance,SetupContext(setup二入参),props
- * @param name 插槽名或者props名
- * @returns VNode
- */
- export default function getSlot(
- {
- instance,
- ctx,
- props = {},
- }: {
- instance?: ComponentPublicInstance;
- ctx?: SetupContext<EmitsOptions>;
- props?: any;
- },
- name = 'default',
- ) {
- const targetSlot = instance?.$slots[name] || ctx?.slots[name];
- return (targetSlot ? targetSlot(instance) : '') || props[name];
- }
|