snippets:vue

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
snippets:vue [2025/10/15 06:50] – [tsx component best practice] lingaosnippets:vue [2025/11/05 12:18] (current) – [tsx slots type] lingao
Line 314: Line 314:
  
 </code> </code>
 +++++
 +
 +==== tsx slots type ====
 +
 +++++ tsx slots type |
 +<codeprism tsx>
 +const Component = defineComponent({
 +  props: {
 +    config: {
 +      type: Array as PropType<EntityInfo[]>
 +    }
 +  },
 +  slots: Object as SlotsType<{
 +    default: ({ foo: string; bar: number }) => JSX.Element
 +  }>,
 +  setup: (props, { slots }) => {
 +    if (props.config == null) throw Error('Config can not be null')
 +    const context = createReferenceInstance(props.config)
 +    provide(refInjectionKey, context)
 +    return () => <>{slots.default && slots.default()}</>
 +  }
 +})
 +
 +const s = new Component().$slots
 +
 +const a = (
 +  <Component>
 +    {
 +      {
 +        default: (scope) => {
 +          scope
 +        }
 +      } as typeof s
 +    }
 +  </Component>
 +)
 +</codeprism>
 ++++ ++++
  • snippets/vue.1760511030.txt.gz
  • Last modified: 2025/10/15 06:50
  • by lingao