posts - 39,comments - 0,views - 33510
在使用el-table实现选择操作的时候,官方提供了一种多选功能,将type设置为selection。而有时候因项目需求,需要进行单选操作,接下来通过一个简单的例子,实现el-table表格单选操作。显然要实现单选,需要用el-radio标签来实现,代码如下:

 

<el-table
ref="multipleTable"
:data="tableData"
:header-cell-style="{background:'#F8F8F9'}"
style="width: 100%;margin-top: 20px">
<el-table-column label="选择" align="center" width="65">
<template scope="scope">
<el-radio :label="scope.$index" v-model="radio"
@change.native="getCurrentRow(scope.row)"></el-radio>
</template>
</el-table-column>
<el-table-column align="center" label="编号" width="160" prop="studentCode"></el-table-column>
<el-table-column align="center" prop="name" label="姓名" width="120"></el-table-column>
<el-table-column align="center" prop="phone" label="账号"></el-table-column>
</el-table>

 

在使用el-radio标签的时候,需要绑定label的值,这里label我绑定的是index,有时候在单选位置是不需要将label的值显示出来,这个时候只需要在el-radio标签里面加上'&nbsp ;'即可。

<el-radio :label="scope.$index"
v-model="radio"
@change.native="getCurrentRow(scope.row)">&nbsp;</el-radio>

 

js代码实现如下:

data: {
return() {
templateSelection: {},
radio: '',
tableData: []
}
}
methods: {
getCurrentRow(row){
// 获取选中数据 row表示选中这一行的数据,可以从里面提取所需要的值
this.templateSelection = row
}
}

 

 

posted on   林多多  阅读(11578)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示