Vue中props类型 设置默认值
props: {
testString: {
type: String,
default: ''
},
testNumber: {
type: Number,
default: 0
},
testBoolean: {
type: Boolean,
default: true
},
testArray: {
type: Array,
default: () => []
},
testObject: {
type: Object,
default: () => ({
})
},
testFunction: {
type: Function,
default: function () {
}
}
}
注意:当默认值为对象时不能写成
testObject: {
type: Object,
default: () => {
}
}
默认写法:
testObject: {
type: Object,
default: function () {
return {
}
}
}