props default 数组/对象的默认值应当由一个工厂函数返回

时间:2023-03-08 22:49:22

export default {
props: {

slides:{
type:Array,
default:[]
}

},这是我的代码

报错是Invalid default value for prop "slides": Props with type Object/Array must use a factory function to return the default value.

// 数组/对象的默认值应当由一个工厂函数返回

// 这是文档里的例子,返回对象
propE: {
type: Object,
default: function () {
return { message: 'hello' }
}
},
// 返回数组的默认值
proE: {
type: Array,
default: function () {
return []
}
}