Vue使用Ant design中a-tree的scopedSlots实现树标题的前后都有icon图标

Vue使用Ant design中a-tree的scopedSlots实现树标题的前后都有icon图标

在这里插入图片描述

<a-tree style="width:100%" :tree-data="treeData" show-icon :default-selected-keys="[treeData[0].key]">
	<!-- 每项 最前面的 箭头的 icon -->
    <a-icon slot="switcherIcon" type="caret-down" />
    <!-- slot="praent" 配合 treeData数据中的 slots 设置目录下 的 icon -->
    <a-icon slot="praent" style="color:#0DD3FF" type="folder-open" />
    <!-- slot="child" 配合 treeData数据children下的 slots 设置children目录 的 icon -->
    <a-icon slot="child" style="color:#FED037" type="folder-open" />
    <!-- 数据中 每个 节点 的 scopedSlots 字段(插槽) 用来设置 所有(子父节点)节点  的 统一的 icon-->
    <template slot="handle" slot-scope="item">
       <!--item.title 为treeData的 title 字段-->
       <span>{{item.title}}</span>
       <a-icon 
         style="position:absolute;right: 0;" 
         @click.stop="treeHandleClick" 
         type="ellipsis" />
     </template>
</a-tree>

<script>
const treeData = [
  {
    title: 'parent 1',
    key: '0-0',
    slots: {icon: 'praent',},
    // ⚠️重点这这里⚠️每一条数据上都添加scopedSlots属性
    scopedSlots:{title:"handle"},
    children: [
      { 
        title: 'leaf', 
        key: '0-0-0', 
        slots: { icon: 'child' },
        scopedSlots:{title:"handle"},
        children: [
          { 
            title: 'leaf', 
            key: '0-0-0-0', 
            slots: { icon: 'child' } ,
            scopedSlots:{title:"handle"},
          },
        ]
      },
    ],
  },
];
</script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值