反選邏輯情況下,需要先toggleRowSelection數(shù)據(jù)挤茄,再給 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();
}
}