I want to use ts types and value default in "defineProps", but it don't work. How can I solve it?
code below
const props = defineProps<{
type?: string
color?: 'color-primary' | 'color-danger' | 'color-plain' | undefined
}>({
type: {
default: 'plain',
},
color: {
default: 'color-plain',
},
})
But it will raise error in ts.
You need to use withDeaults
type Props = {
type?: string
color?: 'color-primary' | 'color-danger' | 'color-plain' | undefined
}
const props = withDefaults(defineProps<Props>(), {
type: 'plain',
color: 'color-plain',
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.