1.引入withDefaults模块,给defineProps绑定默认值。
import { withDefaults } from 'vue'
2.定义Props传输值的类型。
interface Props {
// 类型
type: string;
name: string;
id: number;
}
3.给props的值设置默认值。
const props = withDefaults(defineProps<Props>(), {
type: "性别",
name: "张三",
id: 001,
})
以上vue+ts对于props传值的写法。