1. 程式人生 > 其它 >ElementUI table 中的單選按鈕

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>