vue props default Array或是Object的正确写法
1、错误写法demo:{type:Array,default:[]}eslint语法报错:Invalid default value for prop “demo”: Props with type Object/Array must use a factory function to return the default value.2、正确的写法应该是:demo: {...
·
1、错误写法
demo:{
type:Array,
default:[]
}
eslint语法报错:
Invalid default value for prop “demo”: Props with type Object/Array must use a factory function to return the default value.
2、正确的写法应该是:
demo: {
type: Array,
default: function () {
return []
}
}
或是用箭头函数:
demo: {
type: Array,
default: () => []
}
3、对象的箭头函数写法:
demoObj: {
type: Object,
default: () => ({})
}
或是常规
demoObj: {
type: Object,
default: function () {
return {}
}
}
错误的写法
demoObj: () => {}
更多推荐
已为社区贡献28条内容
所有评论(0)