vue3 props设置默认值

奔跑的哈密瓜 / 2023-07-19 / 原文

1.引入withDefaults

import {  withDefaults } from "vue";

2.使用

const props = withDefaults(defineProps<
{type?:string}
>(),{
    type:'number',
})

 上述代码,设置的是type默认值为number。