【踩坑】el-table调用getSelectionRows方法后,勾选当前行的同时取消勾选了其它行
问题代码:
// 绑定给el-table的data
const groupWorks = computed(() =>
worksGroupByType.value.map((type) => {
return {
...type,
works: [...type.priorityWorks, ...(showRoutineWork.value ? type.normalWorks : [])]
};
}).filter((type) => type.works.length)
);
后来修改了后端数据结构,将priorityWorks和normalWorks合并了,并改成如下方式后,没有问题:
const showWorksGroup = computed(() => {
return worksGroupByType.value.map((type) => {
return {
...type,
works: showRoutineWork.value ? type.works : type.works.filter((work) => work.isPriority)
};
}).filter((type) => type.works.length);
});
原因:
原代码中,work引用是一直在变化的,因为是通过合并priorityWorks和normalWorks来产生一个新数组,引用地址会发生变化。

浙公网安备 33010602011771号