element-ui之el-table翻页后仍然记忆所选项
<el-table
:data="tableData"
style="width: 100%"
border
v-loading="loading"
ref="multipleTable"
@select="handleSelectionChange"
@select-all="handleSelectionChangeAll"
>
<el-table-column type="selection" width="55"> </el-table-column>
</el-table>
getInStoreList() {
this.tableData = res.data;
this.showTag();
},
showTag() {
let handleSelectData = this.multipleSelection || [];
console.log(handleSelectData, "handleSelectData");
for (let i = 0; i < this.tableData.length; i++) {
for (let j = 0; j < handleSelectData.length; j++) {
if (this.tableData[i].rid === handleSelectData[j].rid) {
this.$nextTick().then(() => {
this.$refs.multipleTable.toggleRowSelection(
this.tableData[i],
true
);
});
}
}
}
},
handleSelectionChange(val, row) {
if (val.includes(row)) {
this.multipleSelection.push(row);
} else {
let index = -1;
this.multipleSelection.some((e, i) => {
if (e.rid === row.rid) {
index = i;
return true;
}
});
this.multipleSelection.splice(index, 1);
}
},
handleSelectionChangeAll(val) {
if (val.length === 0) {
this.tableData.forEach((t) => {
let index = -1;
this.multipleSelection.some((e, i) => {
if (e.rid === t.rid) {
index = i;
return true;
}
});
this.multipleSelection.splice(index, 1);
});
} else {
val.forEach((e) => {
let ids = this.multipleSelection.map((m) => m.rid);
if (!ids.includes(e.rid)) {
this.multipleSelection.push(e);
}
});
}
},