父组件中使用自定义的子组件hello,现在传递了两个参数:
<hello :items="languages" :unit="num"></hello>
其中num在父组件的data字段指定具体数值
如果不指定:unit="num",子组件内该怎样判断是否传入了相应的props变量unit?
子组件hello代码:
<template>
</div id="hello">
<ul v=for="item in items">
{{item}}
</ul>
<p>unit:{{unit}}</p>
</div></template><script>export default { props: ['items', 'unit']
}</script>考虑到有些props变量有默认值,有些没有,需要这样写:
props: { items: { // 必须提供字段 required: true
}, unit: { // 可选字段,有默认值 default: 3
}
}
饮歌长啸
随时随地看视频慕课网APP
相关分类