element table Error in callback for watcher “data”: “TypeError: Cannot read properties of null (reading ‘reduce’)”
problem
On the list page, the front-end and back-end joint debugging interface found that the console reported
an error Error in callback for watcher “data”: “TypeError: Cannot read properties of null (reading 'reduce')”
reason
From the prompt, it should be caused by the element table traversing the list data.
Reason 1: The list initialization data is null.
Reason 2: The backend interface returns null and is not processed.
solution
Option 1: Change the list initialization to []
Option 2: Adjust the background interface. When there is no data, return to []
// 方案1
data:{
list: [], // null 改为 []
}
// 方案2 接口数据调整
// 如果接口不能改,只能自己处理
listOrder(bodydata).then(response => {
// this.list = response.data.data.list // before
this.list = response.data.data.list || [] // after
}