先附上效果图
!!!只贴上用到的代码部分!!!
@select 点击复选框的方法,可以只选一行
@row-click 点击某一行,也可以只选一行,并且复选框和行可以随意点,最终仍是只能选中一行
<el-table ref="dataTable" @row-click="handleClickRow" @select="select" >
<el-table-column type="selection" width="50" align="center" />
<el-table-column prop="organName" label="机构名称" :show-overflow-tooltip="true"></el-table-column>
</el-table>
data() {
return {
multipleSelection: [],
};
}
// 点击行
handleClickRow(row, column, event) {
if (this.multipleSelection[0] == row) { // 选中的是已有的 取消选中
this.multipleSelection = [];
this.$refs['dataTable'].clearSelection();
} else {
this.multipleSelection = [row];
this.$refs['dataTable'].clearSelection();
this.$refs['dataTable'].toggleRowSelection(row, true);
}
},
// 点击复选框
select(selection, row) {
if (selection.length > 1) {
const del_row = selection.shift();
this.$refs.dataTable.toggleRowSelection(del_row, false);
}
},
😃 有帮助的话就请你给我点个赞吧~ 如果有写的不完善的地方欢迎指正,共同进步!