
步骤一:<Table ref=“modalTable”:columns=“modalColumns” :data=“testData” border stripe>
步骤二:
data() {
return {
currentChoose: ‘0’,
modalColumns: [
{
title: ‘选择’,
key: ‘id’,
width: 70,
align: ‘center’,
render: (h, params) => {
let id = params.row.id;
let flag = false;
if (this.currentChoose === id) {
flag = true
} else {
flag = false
}
let self = this
return h(‘div’, [
h(‘Radio’, {
props: {
value: flag
},
on: {
‘on-change’: () => {
self.currentChoose = id;
}
}
})
])
}
},
{title: ‘姓名’, key: ‘name’},
{title: ‘手机号’, key: ‘contactPhone’},
]
}}
注意:testData数据中要包含id字段且包含id值数值类型的数据
作者:carry_carrie
来源:CSDN
原文:https://blog.csdn.net/qq_35858002/article/details/88710244
本文介绍如何使用Vue.js实现带有单选功能的表格组件,通过具体代码展示了如何自定义渲染单元格并实现单选逻辑。该方法适用于需要从表格中选择单一记录的应用场景。

2301

被折叠的 条评论
为什么被折叠?



