Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| snippets:vue [2025/10/15 06:50] – [tsx component best practice] lingao | snippets:vue [2025/11/05 12:18] (current) – [tsx slots type] lingao | ||
|---|---|---|---|
| Line 314: | Line 314: | ||
| </ | </ | ||
| + | ++++ | ||
| + | |||
| + | ==== tsx slots type ==== | ||
| + | |||
| + | ++++ tsx slots type | | ||
| + | < | ||
| + | const Component = defineComponent({ | ||
| + | props: { | ||
| + | config: { | ||
| + | type: Array as PropType< | ||
| + | } | ||
| + | }, | ||
| + | slots: Object as SlotsType< | ||
| + | default: ({ foo: string; bar: number }) => JSX.Element | ||
| + | }>, | ||
| + | setup: (props, { slots }) => { | ||
| + | if (props.config == null) throw Error(' | ||
| + | const context = createReferenceInstance(props.config) | ||
| + | provide(refInjectionKey, | ||
| + | return () => <> | ||
| + | } | ||
| + | }) | ||
| + | |||
| + | const s = new Component().$slots | ||
| + | |||
| + | const a = ( | ||
| + | < | ||
| + | { | ||
| + | { | ||
| + | default: (scope) => { | ||
| + | scope | ||
| + | } | ||
| + | } as typeof s | ||
| + | } | ||
| + | </ | ||
| + | ) | ||
| + | </ | ||
| ++++ | ++++ | ||