父组件中使用自定义的子组件hello,现在传递了两个参数:
其中num在父组件的data字段指定具体数值
如果不指定:unit="num",子组件内该怎样判断是否传入了相应的props变量unit?
子组件hello代码:
{{item}}
unit:{{unit}}
考虑到有些props变量有默认值,有些没有,需要这样写:
props: {
items: { // 必须提供字段
required: true
},
unit: { // 可选字段,有默认值
default: 3
}
}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
prop验证
参考 拿走不谢https://github.com/TIGERB/eas...