antdv(vue)组件中tree-select使用

2023-11-13

官网教程:组件tree-select
实现效果:


1.基本用法:直接使用 在vue层写数据

注意:注册组件要包含treeSelect和其中的节点ATreeSelectNode
不注册会报错,如下:

在这里插入图片描述

<template>
   	<a-tree-select
		v-model:value="value"
        show-search
        style="width: 100%"
        :dropdown-style="{ 
        maxHeight: '400px', overflow: 'auto' }"
        placeholder="选择分类..."
        allow-clear
        tree-default-expand-all
        :tree-icon = "true"
      >
         <a-tree-select-node key="0-1" 
         value="parent 1" title="parent 1">
             <a-tree-select-node key="0-1-1" 
             value="parent 1-0" title="parent 1-0">
                 <a-tree-select-node key="random" 
                 value="leaf1" title="my leaf" />
                 <a-tree-select-node key="random1" 
                 value="leaf2" title="your leaf" />
             </a-tree-select-node>
             <a-tree-select-node key="random2" 
             value="parent 1-1" title="parent 1-1">
                 <a-tree-select-node key="random3" value="sss">
                     <template #title><b style="color: #08c">sss</b>					   </template>
                 </a-tree-select-node>
             </a-tree-select-node>
         </a-tree-select-node>
     </a-tree-select>
</template>

<script lang="ts">

import { useForm } from '@ant-design-vue/use';
import {
    getIndustryTree,
    addIndustryTree,
} from '/@/api/industry/index';
import { treeItem } from './type';
import { createVNode, reactive, ref, watch } from 'vue';
import { Form, Modal, Drawer, Input, Button, Select, Switch, Upload, TreeSelect } from 'ant-design-vue';
import { PlusOutlined, LoadingOutlined, CaretDownOutlined, PlusCircleOutlined  } from '@ant-design/icons-vue';
import { message } from 'ant-design-vue';

export default {
    name: 'IndustryDrawer',
    components: {
        [Drawer.name]: Drawer,
        [Form.name]: Form,
        [Form.Item.name]: Form.Item,
        [Input.name]: Input,
        [Input.TextArea.name]: Input.TextArea,
        [Button.name]: Button,
        [Select.name]: Select,
        ASelectOption: Select.Option,
        [Switch.name]: Switch,
        LoadingOutlined,
        PlusOutlined,
        [Upload.name]: Upload,
        [TreeSelect.name]: TreeSelect,
        ATreeSelectNode: TreeSelect.TreeNode,
        CaretDownOutlined,
        PlusCircleOutlined,
    },
    setup(props: any, { emit }: { emit: any }) {
        const value = ref<string>();
		watch(value, () => {
	      	console.log(value.value);
	    });
     
        return {
            value,
        };
    },
};
</script>

2.从数据直接生成

使用 treeData 把 JSON 数据直接生成树结构。

 value:{{valueTree}}
------------
treeData:{{treeData}}

<a-tree-select
    v-model:value="valueTree"
    style="width: 100%"
    :dropdown-style="{ maxHeight: '300px', overflow: 'auto' }"
    :tree-data="treeData"
    placeholder="Please select"
    tree-default-expand-all
>
    <template #title="{ key1, value }">
        <span style="color: #08c" v-if="key1 === '0-0-1'">
        Child Node1 {{ value }}</span>
    </template>
</a-tree-select>

<script lang="ts">
import { useForm } from '@ant-design-vue/use';
import {
    getIndustryTree,
    addIndustryTree,
} from '/@/api/industry/index';
import { treeItem } from './type';
import { createVNode, reactive, ref, watch } from 'vue';
import { Form, Modal, Drawer, Input, Button, Select, Switch, Upload, TreeSelect } from 'ant-design-vue';
import { PlusOutlined, LoadingOutlined, CaretDownOutlined, PlusCircleOutlined  } from '@ant-design/icons-vue';
import { message } from 'ant-design-vue';

interface TreeDataItem {
  value: string;
  key1: string;
  title?: string;
  slots?: Record<string, string>;
  children?: TreeDataItem[];
}

export default {
    name: 'IndustryDrawer',
    components: {
        [Drawer.name]: Drawer,
        [Form.name]: Form,
        [Form.Item.name]: Form.Item,
        [Input.name]: Input,
        [Input.TextArea.name]: Input.TextArea,
        [Button.name]: Button,
        [Select.name]: Select,
        ASelectOption: Select.Option,
        [Switch.name]: Switch,
        LoadingOutlined,
        PlusOutlined,
        [Upload.name]: Upload,
        [TreeSelect.name]: TreeSelect,
        ATreeSelectNode: TreeSelect.TreeNode,
        CaretDownOutlined,
        PlusCircleOutlined,
    },
    props: {
    },
    setup(props: any, { emit }: { emit: any }) {
        // const valueTree = ref<undefined>();
        const valueTree = ref<string>();
        const treeData: TreeDataItem[] = 
        [{
            title: 'Node1',
            value: '0-0',
            key1: '0-0',
            children: [
            {
                value: '0-0-1',
                key1: '0-0-1',
                slots: {
                title: 'title',
                },
            },
            {
                title: 'Child Node2',
                value: '0-0-2',
                key1: '0-0-2',
            },],
        },
        {
            title: 'Node2',
            value: '0-1',
            key1: '0-1',
        },];
       
        const tttt = ref();
        // watch(valueTree, () => {
        //     console.log('valueTree.value', valueTree.value);
        // });
        watch(valueTree, () => {
            console.log(valueTree.value);
        });
       
        // 关联分类选择select
        const onChangeTreeSelect = (value:any) => {
            // valueTree.value = value;
            // console.log('valueTree.value:', valueTree.value);
            console.log('参数value:',value);
            value.value = value;
            console.log('value.value:', value.value);
        };
        return {
            valueTree,
            treeData,
        };
    },
};

3.使用后台接口数据

接口信息:
在这里插入图片描述

如果
在这里插入图片描述

:replace-fields="{children:'children', key:'key1', 
value: 'value', title: 'tit'}"
<template>
     
    <!--抽屉 打开关联分类模态框-->
    <a-drawer
        title="关联分类"
        placement="right"
        :closable="false"
        :data="treeData"
        :visible="showTreeDrawer"
    >
        <a-tree-select
            v-model:value="valueTree"
            style="width: 100%"
            :dropdown-style="{ maxHeight: '300px', overflow: 'auto' }"
            :tree-data="treeData"
            placeholder="Please select"
            tree-default-expand-all
            :replace-fields="{children:'children', key:'key1', value: 'value', title: 'tit'}"
        >
            <!-- <template #title="{ key1, value }">
                <span style="color: #08c" v-if="key1 === '0-0-1'">Child Node1 {{ value }}</span>
            </template> -->
        </a-tree-select>
        <!-- {{tttt}} -->
        <div class="ant-drawer-footer">
            <a-button style="margin-right: 8px" @click="onTreeClose">
                取消
            </a-button>
            <a-button type="primary" @click="onTreeEmitSubmit(value)"> 确认 </a-button>
        </div>
    </a-drawer>
</template>

<script lang="ts">

import { useForm } from '@ant-design-vue/use';
import {
    getIndustryTree,
    addIndustryTree,
} from '/@/api/industry/index';
import { treeItem } from './type';
import { createVNode, reactive, ref, watch } from 'vue';
import { Form, Modal, Drawer, Input, Button, Select, Switch, Upload, TreeSelect } from 'ant-design-vue';
import { PlusOutlined, LoadingOutlined, CaretDownOutlined, PlusCircleOutlined  } from '@ant-design/icons-vue';
import { message } from 'ant-design-vue';


interface TreeDataItem {
  value: string;
  key1: string;
  tit?: string;
  slots?: Record<string, string>;
  children?: TreeDataItem[];
}
export default {
    name: 'IndustryDrawer',
    components: {
        [Drawer.name]: Drawer,
        [Form.name]: Form,
        [Form.Item.name]: Form.Item,
        [Input.name]: Input,
        [Input.TextArea.name]: Input.TextArea,
        [Button.name]: Button,
        [Select.name]: Select,
        ASelectOption: Select.Option,
        [Switch.name]: Switch,
        LoadingOutlined,
        PlusOutlined,
        [Upload.name]: Upload,
        [TreeSelect.name]: TreeSelect,
        ATreeSelectNode: TreeSelect.TreeNode,
        CaretDownOutlined,
        PlusCircleOutlined,
    },
    setup(props: any, { emit }: { emit: any }) {
        const showDrawer = ref(props.visible);
        const ruleForm = ref<typeof Form>();
        // const treeData = ref([]);

        const fileList = ref([]);
        const loading = ref<boolean>(false);
        const imageUrl = ref<string>('');
        // const valueTree = ref<undefined>();
        const valueTree = ref<string>();
        const treeData: TreeDataItem[] = 
        [{
            tit: 'Node1',
            value: '0-0',
            key1: '0-0',
            children: [
            {
                value: '0-0-1',
                key1: '0-0-1',
                // slots: {
                // title: 'title',
                // },
                tit: 'Child Node1',
            },
            {
                tit: 'Child Node2',
                value: '0-0-2',
                key1: '0-0-2',
            },
            ],
        },
        {
            tit: 'Node2',
            value: '0-1',
            key1: '0-1',
        },];
        // const treeData = ref([]);
        const showTreeDrawer = ref(false);
        const tttt = ref();
        watch(valueTree, () => {
            console.log(valueTree.value);
        });
        // 关闭抽屉
        const onClose = () => {
            showDrawer.value = false;
            emit('update:visible', showDrawer.value);
        };
        return {
            valueTree,
            treeData,
        };
    },
};
</script>

在这里插入图片描述

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

antdv(vue)组件中tree-select使用 的相关文章

随机推荐

  • 登录Unity官方商店时提示Sorry, this link is no longer valid.(此链接已失效)

    看了看网上的资料 主要有以下四种方法 第一种非常有效 1 彻底断开当前使用的wifi或者有线网络 打开手机热点 让电脑连接热点 重新登录 就可以进去了 2 关闭魔法 3 打开系统防火墙 设置Unity相关程序为允许专用网络和允许公用网络 都
  • 哨兵-1 Sentinel-1数据下载(欧空局)

    Sentinel 1数据下载 1 Sentinel 1 数据简介 2 Sentinel 1 数据下载步骤 2 1 在欧空局 ESA 下载Sentinel 1 数据 2 1 1网站页面介绍 2 1 2 数据下载步骤 1 Sentinel 1
  • Python pyinstaller打包opencv程序出错(ImportError: OpenCV loader: missing configuration file: [‘config.py‘)

    在打包含有opencv库的程序时 打包 F w 后运行程序报错 运行失败 查看命令行提示 打包时只 F 错误为 ImportError OpenCV loader missing configuration file config py C
  • 数据结构之栈

    栈 什么是栈 1 后进者先出 先进者后出 这就是典型的 栈 结构 2 从栈的操作特性来看 是一种 操作受限 的线性表 只允许在端插入和删除数据 为什么需要栈 1 栈是一种操作受限的数据结构 其操作特性用数组和链表均可实现 2 但 任何数据结
  • Windows应急响应信息采集工具

    项目地址 GitHub ra66itmachine GetInfo Windows Emergency Response 应急响应信息采集 Windows information collection 快速收集 Windows 相关信息 为
  • 全通系统定义、零极点关系、应用

    全通系统定义 表示方法 应用一 将任意因果稳定系统转化为 全通系统和最小相位系统 的级联 应用二 级联一个全通系统可以使非稳定滤波器变成一个稳定滤波器 把非稳定系统的单位圆外的极点映射到单位圆内 应用三 作为相位均衡器 校正系统的非线性相位
  • Android一键清理原理

    欢迎转载 转载请注明 http blog csdn net zhgxhuaa 说明 在总篇中提到过垃圾清理 本篇将着重介绍针对缓存 卸载残留 无用数据等 静态内容 的清理 有关于系统进程的清理以及手机加速的相关功能 将放到 手机加速篇 中介
  • 在腾讯云服务器上安装docker

    一 准备事项 1 1 查看系统版本 uname a docker官方说至少3 8以上 建议3 10以上 root VM 0 11 centos docker uname a Linux VM 0 11 centos 3 10 0 1062
  • 前端面经高频考点

    文章目录 HTML 1 高频1之行内元素 块级元素 行内块元素的区别 2 高频2之script标签中defer和async的区别 3 src和href的区别 4 lable的作用 5 ifram的使用以及有优缺点 6 img的srcset属
  • Java题目练习

    编程题目 题目1 编写MobilePhone类 包含brand 品牌 和price 价格 属性 该类实现Comparable接口规定该类对象大小 即手机能按照价格来排序 2 创建一个只可放 MobilePhone 类的链表 链表当中添加3个
  • geckodriver的安装和测试其是否安装成功

    1 首先下载最新的geckodriver 你可以百度 或者我分享给你 但是如果你看到这篇文的时候 已经更新版本了 你可以去百度一下 总有人在分享的 链接 https pan baidu com s 1L9GLCpLNmgL2szxD6wvK
  • 《科学伦理与学术规范》 课后习题_答案 2022春季

    资料来源网络 侵删 科学伦理与学术规范答案汇总 2022 第一部分 必做 ABC A B D ABCD ABC D A BCD C D D 第二部分 必做 ABCD ABCD ABCD BCD AD A ABCD ACD AC A AC D
  • 了解接口工具Apifox

    最近发现一款接口测试工具 apifox 我我们很难将它描述为一款接口管理工具 或 接口自测试工具 官方给了一个简单的公式 更能说明apifox可以做什么 Apifox Postman Swagger Mock JMeter Apifox的特
  • /usr/bin/ld: cannot find -lmysqlcllient

    文章目录 1 question usr bin ld cannot find lmysqlcllient 2 solution 1 question usr bin ld cannot find lmysqlcllient 2 soluti
  • Unity脚本的属性

    参考官网 http game ceeger com Script Attributes Attributes html http blogs unity3d com 2014 06 24 serialization in unity 参考文
  • 解决UE4启动出现UE4Editor.exe-无法找到dll入口的弹窗

    UE4编辑器启动 一开始遇到的问题如下 上网找问题得到的解答都是在cmd下利用regsvr32 exe注册该dll到注册表 但是也提示报错 上网搜了一下 得知原因是生成该dll的源码没有实现 DllRegisterServer和DllUne
  • 镜像iso文件下载地址

    CentOS 7官方下载地址 https www centos org download Centos国内下载源 以下链接均可下载镜像文件 http man linuxde net download CentOS http centos u
  • 面向对象程序设计语言(Java)-1.概述

    概述 1 Java的两层含义 2 Java语言的特点 3 Java的应用平台 4 Java的工作原理 5 Java环境中的概念 6 初始Java程序 7 Java程序的基本组成 8 开发Java程序的步骤 9 注释 1 Java的两层含义
  • JavaScript中的扁平化数据转换为树形结构、树形结构扁平化数据

    1 扁平化数据 gt 树形结构 1 1 第一种数据类型 原始数据只有id和pId相互关联 let data id 639 name 商品管理 type 0 pId 638 code 1 domain id 640 name 商品分类 typ
  • antdv(vue)组件中tree-select使用

    官网教程 组件tree select 实现效果 1 基本用法 直接使用 在vue层写数据 注意 注册组件要包含treeSelect和其中的节点ATreeSelectNode 不注册会报错 如下