<el-table
ref="Table"
highlight-current-row
border
:data="myMessageList"
max-height="600"
class="table-style"
@select="handleSelectionChange"
@row-click="rowClick"
>
方法:
// 获得当前行数据
handleSelectionChange(selection, row) {
if (this.multipleSelection[0] == row) {
this.multipleSelection = [];
this.$refs["Table"].clearSelection();
} else {
this.multipleSelection = [row];
this.$refs["Table"].clearSelection();
this.$refs["Table"].toggleRowSelection(row, true);
}
console.log(this.multipleSelection[0]);
},
// 表格某一行的单击事件
rowClick(row, column, event) {
// console.log(row)
// 选已选中数据中判断当前点击的是否被选中
if (this.multipleSelection[0] == row) {
// 选中的是已有的 取消选中
this.multipleSelection = [];
this.$refs["Table"].clearSelection();
} else {
this.multipleSelection = [row];
this.$refs["Table"].clearSelection();
this.$refs["Table"].toggleRowSelection(row, true);
}
},
样式:
.table-style /deep/ .el-table-column--selection.is-leaf .el-checkbox {
display: none;
}