报错信息
Error: row is required when get row identity
问题:一直以为是el-table的表数据传输有问题,然后做了一堆排查后发现,其实不然
// 单击或者勾选的数据
selectPage(e) {
if(e.constructor === Array){
this.$refs.maintable.$refs.multipleTable.toggleRowSelection(
e[0],true
)
this.selectRows = e[0]
}else{
this.selectRows = e
this.$refs.maintable.$refs.multipleTable.toggleRowSelection(
e,true
)
}
},
原因分析:
getRowIdentity 此函数参数为空的时候也执行了,所以导致报错
解决方案:
我们只需要在外层加一个判断,在row为空的时候,不触发getRowIdentity函数即可
完整代码:
// 单击或者勾选的数据
selectPage(e) {
//必须要判断是否有选择数据否则toggleRowSelection方法会报错
if(e.constructor === Array && e.length>0){
this.$refs.maintable.$refs.multipleTable.toggleRowSelection(
e[0],true
)
this.selectRows = e[0]
}else{
this.selectRows = e
this.$refs.maintable.$refs.multipleTable.toggleRowSelection(
e,true
)
}
}


博客讨论了一个在 Vue 应用中使用表格组件时遇到的错误:'row is required when getRowIdentity'。作者经过一系列排查,发现问题是由于在调用 `getRowIdentity` 函数时传入了空参数。为了解决这个问题,他们在代码中增加了条件判断,确保在调用该函数之前数据不为空,从而避免了错误的发生。修复后的代码示例展示了如何在数据为空时不触发 `getRowIdentity` 函数,确保了表格操作的稳定性。

1557

被折叠的 条评论
为什么被折叠?



