1、首先看下我之前的写法:
rows.forEach((row) => {
multipleTableRef.value!.toggleRowSelection(row,undefined)
})
怎么尝试都是没办法反选表格的对应列,后来看到一个博主写的解决办法:
list.value是表格的data内容:
nextTick(() => {
list.value.forEach(item => {
let result = rows.find(row => row.id == item.id);
if (result) {
multipleTableRef.value.toggleRowSelection(item, true);
}
});
});
完整内容:
<el-table ref="multipleTableRef" v-loading="loading" :data="list" @selection-change="handleSelectionChange" row-key="id" height="300" > <el-table-column type="selection" width="50" /> </el-table>
const toggleSelection = (rows?: []) => {
if (rows) {
nextTick(() => {
list.value.forEach(item => {
let result = rows.find(row => row.id == item.id);
if (result) {
multipleTableRef.value.toggleRowSelection(item, true);
}
});
});
} else {
multipleTableRef.value.clearSelection()
}
}
踩坑之路,仅供大家参考