VUE_props默认值为数组或对象时报错Invalid default value for prop “categories“: Props with type Object/Array must
Invalid default value for prop “categories”: Props with type Object/Array must use a factory function to return the default value.
found in
- 翻译过来:类型为Object/Array的属性必须使用工厂函数返回默认值
错误写法
props:{
categories: {
type:Array,
default:[1,2]
}
},
正确写法
props默认值是数组或是对象时应该以函数返回
props:{
categories: {
type:Array,
default:function () {
return ['1', '2', '3', '4', '5', '6']
}
},
},