
默認表格前面的復選框是可以選擇多個,但有的需求是只能選擇一個,
可以通過clearSelection和toggleRowSelection去實現,把當前選中的這條selected設置成true。
<div class="same-table">
<el-table
:data="tableData"
class="oneTabel"
ref="multipleTable"
border
fit
@selection-change="handleSelectionChange"
@select-all="dialogCheck"
@select="dialogCheck"
style="width:100%;">
<el-table-column type="selection" width="50"></el-table-column>
<el-table-column type="index" width="60" label="序號"></el-table-column>
<el-table-column prop="name" label="機構"></el-table-column>
<el-table-column prop="negativeDec" label="負面清單描述"></el-table-column>
</el-table>
</div>
methods: {
handleSelectionChange(val) {
console.log(val, 'val')
this.multipleSelection = val;
},
dialogCheck: function(selection, row) {
console.log(selection, row);
this.$refs.multipleTable.clearSelection()
if (selection.length === 0) {
return
}
if (row) {
this.selectioned = row
this.$refs.multipleTable.toggleRowSelection(row, true)
}
}
}
