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>

 

 

 
posted @ 2022-04-19 10:09  三寸日光  阅读(2425)  评论(0)    收藏  举报