ElementUI table 中的單選按鈕


常見的組件中都是復選框,如果把復選框改為單選按鈕,詳細如下:

代碼

<el-table :data="gatewayTableData " border class="table"
ref="gatewayTable" style="margin-top: 10px"
height="360" v-loading="loadingShow"
@current-change="updateCurrentGateway"
highlight-current-row
>

<el-table-column label="" width="35" align="center">
    <template slot-scope="scope">
<el-radio :label="scope.row.id32" v-model="radio"
@change.native="getCurrentGateway(scope.row)"
style="color: #fff;"></el-radio>
</template>
</el-table-column>
<el-table-column prop="index" label="序號" width="55">
<template slot-scope="scope">
<span>{{scope.$index +1}}</span>
</template>
</el-table-column>
</el-table>

<script>
  export default(){
    data:return{
      radio:'',//關聯的單選按鈕
    },
    methods:{
      //單選選中
      getCurrentGateway(row){
      this.gatewaySelectData = row;
      },
      //點擊選中的行也可以選中單選按鈕
      updateCurrentGateway(row){
     //如果沒有row,終止
    if(!row) return;
    //把當前行label綁定的值和v-model綁定的值相同時,單選按鈕就可以選中
     this.radio = row.id32;
    this.gatewaySelectData = row;
   } 
  }
<script>

 

 

 


免責聲明!

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



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