1.想要实现查出来数据之后根据条件判断是否自动选中
<el-table
:data="state.List"
highlight-current-row
ref="singleTable"
@selection-change="handleSelectionChange"
>
<el-table-column type="selection" width="55" align="center"></el-table-column>
<el-table-column prop="limitType" label="限制等级" width="100" show-overflow-tooltip></el-table-column>
</el-table>
上面的 ref="singleTable", @selection-change="handleSelectionChange"是必须的。
查询出结果之后:
_this.$refs.singleTable.clearSelection()
nextTick(() => {
state.List.forEach((row) => {
if (row.limitType == 1) {
_this.$refs.singleTable.toggleRowSelection(row)
}
})
})
其中,这一步代码:
_this.$refs.singleTable.clearSelection()
最好加上,如果不加,可能会出现,无法默认选中的情况。