ant-design-vue:a-table表格中插入自定义按钮

3 篇文章 0 订阅

本文将介绍如何使用ant-design-vue在a-table表格中加入自定义按钮和图标的代码。

结果如下图所示,

在这里插入图片描述

一、简单示例

<template>
  <a-table
    :columns="columns"
    :data-source="data"
    :row-selection="rowSelection"
    :ellipsis="true"
    class="custom-table"
  >
    <template #download="{ record }">
      <a-button type="primary" ghost>编辑</a-button>
    </template>
  </a-table>
</template>

columns 里面加上 slots: { customRender: 'download' }, download和上面 <template #download="{ record }">中的download保持一致。

const columns = [
    {
      title: '操作',
      dataIndex: 'operation',
      key: 'operation',
      width: '11%',
      ellipsis: true,
      slots: { customRender: 'download' },
    },
  ];

二、复杂示例

<template>
  <a-table
    :columns="columns"
    :data-source="data"
    :row-selection="rowSelection"
    :ellipsis="true"
    class="custom-table"
  >
    <template #video="{ record }">
      <a-button type="primary" ghost>视频</a-button>
    </template>
    <template #image="{ record }">
      <a-button type="primary" ghost>图片</a-button>
    </template>
    <template #operation="{ record }">
      <DownloadOutlined />
      <DeleteOutlined />
    </template>
  </a-table>
</template>

columns 里面加上 slots: { customRender: 'video' }, video和上面 <template #video="{ record }">中的video保持一致。

columns 里面加上 slots: { customRender: 'image' }, image和上面 <template #image="{ record }">中的image保持一致。

columns 里面加上 slots: { customRender: 'operation' }, operation和上面 <template #operation="{ record }">中的operation保持一致。


<script lang="ts" setup>

  import { Table as ATable, Tag as ATag } from 'ant-design-vue';
  import {
    PictureOutlined,
    DownloadOutlined,
    DeleteOutlined,
    PlayCircleOutlined,
  } from '@ant-design/icons-vue';

  const columns = [
    {
      title: '视频',
      dataIndex: 'video',
      key: 'video',
      width: '11%',
      ellipsis: true,
      slots: { customRender: 'video' },
    },
    {
      title: '图片',
      dataIndex: 'image',
      key: 'image',
      width: '11%',
      ellipsis: true,
      slots: { customRender: 'image' },
    },
    {
      title: '操作',
      dataIndex: 'operation',
      key: 'operation',
      width: '11%',
      ellipsis: true,
      slots: { customRender: 'operation' },
    },
  ];

</script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值