<!-- reserve-selection:仅对 type=selection 的列有效,类型为 Boolean,为 true 则会在数据更新之后保留之前选中的数据(需指定 row-key) -->
<table ref="tableRef" @selection-change="checkClick" :row-key="rowKey">
<table-column type="selection" :reserve-selection="true"></table-column>
</table>
checkClick(selection) {
this.selection = selection;
}
rowKey(row) {
return row.cartId;
}
watch: {
// val:表格数据源
goodList(val) {
val.forEach(item => {
// 表中选中的数据列表
vue.selection.forEach(self => {
if(self.cartId === self.cartId) {
// 更新当前行的选中状态
vue.$refs.tableRef.toggleRowSelection(item, true);
}
})
})
}
}