element表格實現復選框單選


 

默認表格前面的復選框是可以選擇多個,但有的需求是只能選擇一個,

可以通過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)
            }
        }
}

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM