反选逻辑情况下,需要先toggleRowSelection数据,再给 tableData赋值,才能正常选中。
正选情况下,toggleRowSelection,必须从选择tableData中toggleRowSelection Item才能选中。
<el-table
ref="multiTable"
:data="dataList"
stripe
row-key="id"
@selection-change="selectionChange"
>
<el-table-column prop="id" label="模板ID" min-width="150">
</el-table-column>
<el-table-column
align="center"
:reserve-selection="true"
type="selection"
width="85"
>
</el-table-column>
</el-table>
/**
* 反选
*/
setChecked() {
this.$nextTick(() => {
this.tableChecked.forEach((item) => {
(this.$refs.multiTable as HTMLFormElement).toggleRowSelection(
item,
true
);
});
});
}
/** 生命周期 */
mounted() {
const selected = this.selected.map((item) => {
return {
id: item
};
});
this.tableChecked = selected;
this.setChecked();
setTimeout(() => {
this.dataList = [{ id: 1, name: "lpl", status_txt: "已上架" }];
}, 1000);
// this.getList();
}
}