首先,把全选框隐藏。
.el-table__header-wrapper .el-checkbox{
//找到表头那一行,然后把里面的复选框隐藏掉
display:none
}
给el-table绑定@selection-change和@current-change事件
<el-table height="250" :data="addButtonData.incomeRuleList" @selection-change="selectChargeRule" @current-change="currentChange" ref="selectChargeRuleRef">
<el-table-column type="selection"></el-table-column>
<el-table-column prop="id" label="规则ID"></el-table-column>
</el-table>
// 当多选时,去除全部选择,勾选最后一个选项
selectChargeRule (val) {
if (val.length > 1) {
this.$refs.selectChargeRuleRef.clearSelection()
this.$refs.selectChargeRuleRef.toggleRowSelection(val[val.length - 1])
}
this.selectedRule = val[val.length - 1]
},
// 点击一行的任意位置就勾选上
currentChange (val) {
this.$refs.selectChargeRuleRef.toggleRowSelection(val)
},