vue3+ant 2.x tabls表格内容的自定义和插槽使用

1.表格内容的自定义,后端接口数据返回的数据有时是状态码,例如0和1,0代表未通过,1代表通过,此时我们肯定不能在表格上显示0或1,这时就用到表格自定义

 const columns2 = ref([   colums2表格头数据
    {
      title: "序号",
      key: "index",
      customRender: ({ text, record, index }) => `${index + 1}`,
    },
    {
      title: "登录账户",//表格头数据
      dataIndex: "login",//接口返回值与此表格头数据绑定
      key: "login",
    },
    {
      title: "姓名",
      dataIndex: "name",
      key: "name",
      ellipsis: true,
    },
    {
      title: "用户组",
      dataIndex: "orgId",
      key: "orgId",
    },
    {
      title: "状态",
      dataIndex: "activated",
      customRender: (val) => {//根据接口返回值自定义渲染数据
        // customRender属性是一个方法,可接收三个参数(val,row,index),分别是当前值、当前行数据和当前索引 
        return val.text == 1 ? "正常" : "未激活";
      },
      key: "activated",
    },

2.在表格内使用插槽

html代码

         <a-table
              :dataSource="dataSource1"
              :columns="columns1"
              rowKey="sign"
              :pagination="pagination"
            >
              //插槽start
              <template #action="{ record }">//#action与表格columns数据关联,columns数据在js
                <span>
                  <a @click="inHandle(record)"
                    ><InGroup :ingroup="ingroup"
                  /></a>
                  <a-divider type="vertical" />
                  <a>停用</a>
                  <a-divider type="vertical" />
                  <a class="ant-dropdown-link"> 删除 </a>
                </span>
              </template>
              //插槽end
            </a-table>

colimns数据

const columns1 = [
    {
      title: "登录名",
      dataIndex: "one",
      key: "one",
    },
    {
      title: "姓名",
      dataIndex: "two",
      key: "two",
    },
    {
      title: "英文名",
      dataIndex: "there",
      key: "there",
    },
     
    {
      title: "操作",
      key: "action",
      slots: { customRender: "action" },//自定义插槽
    },
  ];

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值