iview中Table单选

iview中Table实现单选功能,先看图

fxg

html

<Table class="table_son1"  border  :columns="tableColumns2" :data="tableData2" ></Table>

对应的js

tableColumns2: [
   {
     title: '选择',
     width: 60,
     align: 'center',
     render: (h, params) => {
       return h('Radio', {
         props: {
           value: params.row.isselected
         },
         on: {
           'on-change': () => {
             this.ids = params.row.id
             this.systemVersionIssueId = params.row.systemVersionId
             this.tableData2.forEach(items => { // 每次选中下一条数据时将每一条数据设为false
               // items.tag=false      错误,使用$set设置
               this.$set(items, 'isselected', false)// 正确 
             })
             this.tableData2[params.index].isselected = true // 当前数据设为已选中状态
             // console.log(this.tableData2, '数据打印')
             // console.log(params, 'params', this.ids, this.systemVersionIssueId)
           }
         }
       })
     }
   }, {
     title: '关键词',
     align: 'center',
     key: 'keyword',
     width: 150
   }, {
     title: '摘要',
     key: 'summary',
     align: 'center',
     render: (h, { row, index, column }) => {
       return h('div', row.summary ? row.summary : '')
     }
   }
 ], // 列render

接口数据处理

if (res.success) {
   _this.tableData2 = res.result
   res.result.map(item => {
     Object.assign(res.result[0], { isselected: false }) // 拷贝一个是否选中字段 isselected
   })
   _this.tableData2 = res.result
 }
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值