antd-vue中table用法心得

  const columns = [
    {
        title: '等级',
        dataIndex: 'degree',
        key: 'degree',
        scopedSlots: { customRender: 'degree' },
    }, {
        title: '告警名称',
        dataIndex: 'name',
        key: 'name',
        scopedSlots: { customRender: 'name' },
    }, {
        title: '受影响范围',
        key: 'area',
        dataIndex: 'area',
        scopedSlots: { customRender: 'area' }, //在某一列中,可以通过配置scopedSlots这个属性来配置支持slot-scope的属性
    }, {
        title: '处理时间',
        key: 'time',
        dataIndex: 'time',
        // scopedSlots: { customRender: 'time' },
    },{
        title: '操作',
        key:'operator',
        dataIndex:'operator',
        scopedSlots: { customRender: 'operator' }
    }
    ];

1.首先定义表格的所有列的数据,其中scopedSlots官方解释说在某一列中,可以通过配置scopedSlots这个属性来配置支持slot-scope的属性,

大致的意思就是某一列通过使用了scopedSlots这个属性之后在table中
<a-table :columns="columns" :dataSource="data" :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}" :pagination="false"
                 :scroll="{y: 600 }">
            <span slot="degree" slot-scope="tags">
                <a-tag v-for="tag in tags"  :color="tagColor(tags)">{{tag}}</a-tag>
            </span>
            <span slot="name" slot-scope="names,record">
                <a v-for="name in names"  @click="showDrawer(record)">{{name}}</a>
            </span>
            <span slot="operator" slot-scope="text, record">
              <a href="javascript:;"  @click="showConfirm(record)">{{record.state === 1?'':'处理'}}</a>
            </span>
</a-table>
可以通过对其中一列的数据自定义,比如我们并没有对操作这一列进行赋值如下图所示,因此我们就可以通过
<span slot="operator" slot-scope="text, record">
           <a href="javascript:;"  @click="showConfirm(record)">{{record.state === 1?'':'处理'}}</a>
 </span>
 对操作这一列的数据进行自定义的处理

在这里插入图片描述
在这里插入图片描述
2.如图所示中等级的那一列,数据是通过循环遍历出来的,假如我们希望对其中文字内容的不一样显示不一样的背景色,

 <span slot="degree" slot-scope="tags">
            <a-tag v-for="tag in tags"  :color="tagColor(tags)">{{tag}}</a-tag>
  </span>
  假如不用tag标签可以用:class=“...."进行设置
  data(){
  	return {
  		 tagColor:function (name) {
                    if(name[0] === '一般'){
                        return '#f50'
                    }else if(name[0] === '紧急'){
                        return '#C60000'
                    }
                },
  	}
  }
  通过以上这种方式就可以达到如上图所示的效果

3.当我们点击处理的时候,希望得到当前行的数据

<span slot="operator" slot-scope="text, record">
           <a href="javascript:;"  @click="showConfirm(record)">{{record.state === 1?'':'处理'}}</a>
 </span>
 其中的record就是当前行的数据

在这里插入图片描述
这一步主要参考了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值