首先多选这一列需要添加属性 reserve-selection,在table上绑定row-key,我这里绑定的是数据的id属性,并且绑定ref变量multipleTableRef
<el-table-column reserve-selection type="selection" width="55" />
<el-table
ref="multipleTableRef"
@row-click="onPreview"
:data="questionPage"
row-key="id"
@selection-change="handleSelectionChange"
>
下一步回显方法参考官网 其中rows数据只要有属性和表格数据row-key对应即可,回显时记得比较一下是否在已选中列表内,要不然辉重复
//回显示 需要给出row-key相同的数据
const toggleSelection = (rows) => {
if (rows) {
rows.forEach((row) => {
multipleTableRef.value?.toggleRowSelection(row, undefined)
})
} else {
multipleTableRef.value?.clearSelection()
}
}