Vue--Props with type Object/Array must use a factory function to return the default value.
Vue--Props with type Object/Array must use a factory function to return the default value.问题描述解决办法问题描述今天在学习小马哥的购物车demo时发生该问题,翻译下标蓝的提示信息,我们可以知道如果props类型为Object/Array则usea factory function to return the
·
问题描述
今天在学习小马哥的购物车demo时发生该问题,翻译下标蓝的提示信息,我们可以知道如果props类型为Object/Array 则use a factory function to return the default value,同时网上也有参考大佬们的解决办法❤,在此记录下
解决办法
// 报错代码
props: {
cartList: {
type: Array,
default:[]
}
},
// 正解1 箭头函数
props: {
cartList: {
type: Array,
default:()=>[]
}
}
// 正解2
props: {
cartList: {
type: Array,
default:function(){
return [];
}
}
},
更多推荐
所有评论(0)