If the incoming data does not meet the specifications, Vue (development version) will generate a console warning.
<template>
<div>
<example :propA="'hello'" :propB="{hello:'hello'}" :propC="''" :propD="'hello'" :propE="{hello:'hello'}" :propF="10"></example>
</div>
</template>
Vue.component('example', {
props: {
propA: Number, // 数字类型 (`null` 意思是任何类型都可以)
propB: [ String, Number ], // 多种类型:字符串、数字类型
propC: {
type: String, required: true }, // 字符串、必传
propD: {
type: Number, default: 100 }, // 数字,有默认值
// 数组、对象的默认值应当由一个工厂函数返回
propE: {
type: Object,
default: function () {
return {
message: 'hello1' }
}
},
// 自定义验证函数
propF: {
validator: function (value) {
return value > 10
}
}
}
})
Note: The verification specification needs to be in the form of an object, not a string array