A factory function in props looks like this:
props: {
exampleDefaultObject: {
type: Object,
default() {
return {}
}
},
exampleDefaultArray: {
type: Array,
default() {
return []
}
}
},
or in ES6:
props: {
exampleDefaultObject: {
type: Object,
default: () => ({})
},
exampleDefaultArray: {
type: Array,
default: () => []
}
},
(for people who come here looking for an explanation of the error in the question 'props with type object/array must use a factory function to return the default value')
Note that when returning an object in an es6 arrow function, you need the parentheses: () => ({})
instead of () => {}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…