1、设置属性:@selection-change=“handleSelectionChange”
<el-table
:data="taskList"
ref="tableDataRefs"
@selection-change="handleSelectionChange"
:header-cell-class-name="hideAllCheckbox"
>
function handleSelectionChange(selection) {
if (selection.length > 1) {
// 如果选择了多个,只保留最后一个
selectedRow.value = selection[selection.length - 1];
let del_row = selection.shift();
// 其余的都不选中
tableDataRefs.value.toggleRowSelection(del_row, false);
} else {
selectedRow.value = selection.length ? selection[0] : null;
}
}
2、使用动态css 隐藏顶部全选框。添加属性::header-cell-class-name=“hideAllCheckbox”
function hideAllCheckbox({ row, column, rowIndex, columnIndex }) {
if (columnIndex === 0) return "setDisable";
}
<style lang="scss" scoped>
:deep(.setDisable) {
.cell {
visibility: hidden;
}
}
</style>