一、仅声明类型:
const props = defineProps<{
sourceList: KnLib.LibSource[]
}>()
二、使用箭头函数声明:
const $props = defineProps({
sourceList: {
type: Array as () => KnLib.LibSource[],
required: true,
default: () => [{ name: '文件1' }, { name: '文件2' }]
}
})
三、使用withDefaults来指定默认值:
type Props = {
selectedNodeId: string
selectedEdgeId: string
graph: any
}
const $props = withDefaults(defineProps<Props>(), {
selectedNodeId: '',
selectedEdgeId: '',
graph: {}
})