ElementUI el-table 表格 行选择框改为单选

首先,表格加一列

<el-table-column type="selection" width="55"></el-table-column>

然后,隐藏掉标头的全选全不选

thead .el-table-column--selection .cell{
    display: none;
}

给表格加一个 ref,例如:ref="Table" (加在el-table的属性里)
给表格加一个事件 @selection-change="chooseInstance"

chooseInstance (val) {
    if (val.length > 1) {
        this.$refs.Table.clearSelection()
        this.$refs.Table.toggleRowSelection(val.pop())
    } else {
    }
},

如果要实现点击表格的行就单选,再添一个 @current-change 事件:
在事件中:

currentChange(currentRow, oldCurrentRow) {
    this.$refs.Table.toggleRowSelection(currentRow)
}

猜你喜欢

转载自www.cnblogs.com/wbyixx/p/11934719.html