elementUI-table中点击行和radio按钮都可以实现单选

本文介绍在 ElementUI 的 table 组件中实现单选功能的方法。通过绑定 materialId 到 el-radio 和监听 current-change 事件,使得点击行或单选按钮都能实现单选效果,同时介绍了如何获取当前选中行的数据。

elementUI-table中点击行和radio按钮都可以实现单选

		<el-table
          :data="mlist"
          highlight-current-row
          border
          style="width: 100%"
          @current-change="handleCurrentChange">
          	<el-table-column label="" width="35" align="center">
              <template slot-scope="scope">
                  //label设置不同标识
                  <el-radio :label="scope.row.materialId"  v-model="tempRadio" 								@change="getTemplateRow(scope.row)"></el-radio>
              </template>
          </el-table-column>
			//省略
			//......
		</el-table>
	//currentRow和tempRadio是全局定义的变量
	//选中按钮时获取当前行数据
    selectHandle(index,row){                            
        this.currentRow = row;
    },
     //点击表格中每一行也能选中单选按钮,选择改行数据   
     handleCurrentChange(row){
         //如果没有row,终止
         if(!row) return
         //把当前行label绑定的值和v-model绑定的值相同时,单选按钮就可以选中
         this.tempRadio = row.materialId
         this.currentRow = row
     }

在这里插入图片描述

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值