antd + vue3实现tree树增加按钮

本文介绍如何在Vue3项目中结合Ant Design Vue库,利用slot特性为Tree组件添加自定义按钮。强调接口返回数据需包含title, key, children字段,避免与API冲突。" 103923423,9178892,C++中删除map和set元素的方法,"['C++编程', '数据结构', '容器操作']
摘要由CSDN通过智能技术生成

页面显示
在这里插入图片描述

写在前面

改代码使用slot,接口返回值必须为title,key,children,不能使用API在这里插入图片描述
这个会导致我们按钮的slot冲突

完整代码

<template>
  <div class="department">
    <a-card title="部门管理" :bordered="false">
      <div>
        <a-row class="departmentTitle">
          <a-col :span="10">部门名称</a-col>
          <a-col :span="10">部门负责人</a-col>
          <a-col :span="4" style="text-align:center">操作</a-col>
        </a-row>
      </div>

      <a-tree
        ref="tree1"
        :load-data="onLoadData"
        :tree-data="treeData"
        :defaultExpandAll="false"
        :selectedKeys="selectedKeys"
        blockNode
      >
        <template v-slot:title="nodeData">
          <a-row>
            <a-col :span="10">{
   {
    nodeData.title }}</a-col>
            <a-col :span="10">{
   {
    nodeData.dataRef.owner }}</a-col>
            <a-col :span="4">
              <a-button-group style="float:right">
                <a-button size="small" @click="addNode(nodeData)"
                  >新增下级</a-button
                >
                <a-button size="small" @click="editNode(nodeData)"
                  >修改</a-button
                >
                <a-popconfirm
                  title="确认删除该部门?"
                  ok-text="确认"
                  cancel-text="取消"
                  @confirm="deleteNode(nodeData)"
                >
                  <a-button size="small">删除</a-button>
                </a-popconfirm>
              </a-button-group>
            </a-col>
          </a-row>
        </template>
      </a-tree>
      <a-modal
        v-model:visible="visible"
        :title="modalTitle"
        @ok="handleOk"
        @cancel="resetForm"
        okText="确认"
        cancelText="取消"
        :maskClosable="false"
        :closable="false"
      >
        <a-form
          ref="formRef"
          :model="formState"
          :rules="rules"
          :label-col="labelCol"
          :wrapper-col="wrapperCol"
        >
          <a-form-item ref="depName" label="部门名称" name="depName">
            <a-input
              v-model:value="formState.depName"
              placeholder="请输入部门名称"
              :disabled="formState.disabled"
            />
          </a-form-item>
          <a-form-item ref="depPerson" label="部门负责人" name="depPerson">
            <a-input
              v-model:value
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lbchenxy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值