props: {
rowClick: {
type: Function,
default: function() {}
},
title: {
type: String,
default: "标题"
},
display: {
type: String,
default: "table"
},
columnCount: {
type: Number,
default: 4
},
columns: {
type: Array,
default() {
return [];
}
},
showPage: {
type: Boolean,
default: true
},
api: {
type: Object,
default() {
return {};
}
}
},
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: () => {}
---------------------