在以前的vue3 + js中的写法为:
<script lang=ts setup>
const props = defineProps({
title:{
type:String,
defalut:'默认标题' //默认值
required:true // 是否必传
}
})
vue3 + ts 写法 使用withDefaults设置默认值
<script lang=ts setup>
const props = withDefaults(defineProps<{
title?: string,
count?: number,
id?: number
}>(), {
title: '默认标题',
count: 0,
id: 8
})