<el-table
ref="multipleTable"
:data="leftList"
style="width: 100%"
:row-key="getRowKey"
@selection-change="handleSelectionChange"
>
<el-table-column
type="selection"
width="55"
:reserve-selection="true"
/>
<!-- 其他列 -->
</el-table>
getRowKey(row) {
return row.id;
},
/**
* 左侧切换选择状态
* @param {Array} arr 选中的项目
*/
handleSelectionChange(arr) {
this.rightList = arr;
if (arr.length > 0) {
const ids = arr.map((e) => e.id);
this.leftList = this.leftList.filter((e) => !ids.includes(e.id));
this.leftList.unshift(...arr);
}
},
这个方法相当于缓存当前选中项,重新赋值的时候,不会重新走切换选中状态,所以在使用中,如有需求,要主动清理掉选中状态
this.$refs.multipleTable.clearSelection();