props: {
stringProps: {
type: String,
default: ''
},
numberProps: {
type: Number,
default: 0
},
booleanProps: {
type: Boolean,
default: true
},
arrayProps: {
type: Array,
default: () => []
},
objectProps: {
type: Object,
default: () => ({})
},
functionProps: {
type: Function,
default: function () { }
}
}
//其中,默认值为Object时,不能写成
demoObject: {
type: Object,
default: () => { }
}
// 不加’()'的话返回的是一个空函数体,没有返回值。
// 默认写法
demoObject: {
type: Object,
default: function () {
return {}
}
}
Vue中props类型及默认值
最新推荐文章于 2024-05-17 08:00:00 发布