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/09/09 08:09] – lingao | snippets:vue [2025/11/05 12:18] (current) – [tsx slots type] lingao | ||
|---|---|---|---|
| Line 3: | Line 3: | ||
| <code tsx> | <code tsx> | ||
| - | import { computed, defineComponent, | + | import { computed, defineComponent, defineProps, type PropType } from ' |
| - | const props = { | + | type ModelType |
| - | modelValue: { | + | |
| - | | + | |
| - | default: () => ({}) | + | |
| - | }, | + | |
| - | ' | + | |
| - | type: Function as PropType< | + | |
| - | } | + | |
| - | } | + | |
| export default defineComponent({ | export default defineComponent({ | ||
| - | props, | + | props: { |
| + | modelValue: { | ||
| + | type: Object as PropType< | ||
| + | default: () => ({} as ModelType), | ||
| + | }, | ||
| + | ' | ||
| + | type: Function as PropType< | ||
| + | }, | ||
| + | }, | ||
| setup(props) { | setup(props) { | ||
| - | const { ' | ||
| const modelValue = computed({ | const modelValue = computed({ | ||
| get() { | get() { | ||
| - | return props.modelValue | + | return props.modelValue; |
| }, | }, | ||
| - | set(val) { | + | set(val: ModelType) { |
| - | | + | |
| - | } | + | }, |
| - | }) | + | }); |
| - | return () => <></> | + | |
| - | } | + | return () => <></> |
| - | }) | + | }, |
| + | }); | ||
| </ | </ | ||
| Line 313: | 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 | ||
| + | } | ||
| + | </ | ||
| + | ) | ||
| + | </ | ||
| ++++ | ++++ | ||