效果:第一页选中1,2两条数据;翻页到第二页 选中1条数据;返回第一页1,2两条数据仍是选中状态
实现代码:
<template>
<el-table
ref="multipleTableRef"
:data="tableData"
style="width: 100%"
@selection-change="handleSelectionChange"
:row-key="tableRowKey"
>
<el-table-column type="selection" width="55" reserve-selection />
<el-table-column label="Date" width="120">
<template #default="scope">{{ scope.row.date }}</template>
</el-table-column>
<el-table-column property="name" label="Name" width="120" />
<el-table-column property="address" label="Address" show-overflow-tooltip />
</el-table>
</template>
<script>
const tableRowKey = ref('id')
</script>
总结:
1.el-table 绑定属性row-key为tableRowKey,以表格中每条数据的id作为rowKey
2.给 type="selection" 的el-table-column 添加属性 reserve-selection