antdesign树形表格自定义展开图标

 

 

<template>
  <a-table :columns="columns" :data-source="data" rowKey="id" :defaultExpandAllRows="true">
    <template #headerCell="{ column }">
      <template v-if="column.key === 'action'">
        <!-- 添加 -->
        <span><plus-circle-outlined class="add" /></span>
      </template>
    </template>
    <template #bodyCell="{ column, record }">
      <template v-if="column.key === 'action'">
        <!-- 添加 -->
        <span><plus-circle-outlined class="add" /></span>
        <!-- 编辑 -->
        <span><form-outlined class="edit" /></span>
        <!-- 删除 -->
        <span><minus-circle-outlined class="delete" /></span>
      </template>
    </template>
    <!-- 自定义展开图标 -->
    <template #expandIcon="props">
      <caret-right-outlined v-if="!props.expanded && props.record.children"
        @click="clickIcon(props.record, props.onExpand)" />
      <caret-down-outlined v-if="props.expanded && props.record.children"
        @click="clickIcon(props.record, props.onExpand)" />
    </template>
  </a-table>
</template>
<script setup>
import { ref, reactive } from 'vue';
import Icon, { PlusCircleOutlined, FormOutlined, MinusCircleOutlined, CaretRightOutlined, CaretDownOutlined } from '@ant-design/icons-vue';
const columns = [
  {
    title: '名称',
    dataIndex: 'name',
    key: 'name',
  },
  {
    title: '顺序',
    dataIndex: 'sort',
    key: 'sort',
  },
  {
    title: '操作',
    dataIndex: 'action',
    key: 'action',
    width: '15%'
  },
];
const data = [
  {
    id: 1,
    name: 'John Brown sr.',
    sort: 1,
    children: [
      {
        id: 11,
        name: 'John Brown',
        sort: 1
      },
      {
        id: 12,
        name: 'John Brown jr.',
        sort: 2,
        children: [
          {
            id: 121,
            name: 'Jimmy Brown',
            sort: 1,
          },
        ],
      },
      {
        id: 13,
        name: 'Jim Green sr.',
        sort: 3,
        children: [
          {
            id: 131,
            name: 'Jim Green',
            sort: 1,
            children: [
              {
                id: 1311,
                name: 'Jim Green jr.',
                sort: 1
              },
              {
                id: 1312,
                name: 'Jimmy Green sr.',
                sort: 2
              },
            ],
          },
        ],
      },
    ],
  },
  {
    id: 2,
    name: 'Joe Black',
    sort: 2
  },
];
function clickIcon (record, onExpand) {
  onExpand(record)
}
</script>
<style scoped>
.add {
  @apply text-base;
  color: #52c41a
}

.edit {
  @apply text-base mr-2 ml-2;
  color: #0000009c
}

.delete {
  @apply text-base;
  color: #ff7875
}
</style>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值