簡單粗暴直接上代碼:
// 這樣寫時會報錯 Type of the default value for 'record' prop must be a function
props: {
record: {
type: Array,
default: []
}
}
// 正確應該這樣寫
// 因為vue規定,對象或數組默認值必須從一個工廠函數獲取
props: {
record: {
type: Array,
default: function () {
return []
}
}
}
data() {
return {
newRecord: this.record
// record直接使用如果報錯,可以先賦值給另外的變量,再進行其他操作
}
}
