Vue 树状结构控件

1、效果图如下所示:

2、网络请求的数据结构如下:

3、新建插件文件:menu-tree.vue,插件代码如下:

<template><div class="root"><div class="parent" @click="onParentClick(parentItem)"><div class="parent-rectangle" :style="{ 'width': i == 1 ? '24px' : '32px' }" v-for="i in currentLevel - 1" :key="i"></div><div class="parent-right"><img class="parent-icon" :src="getParentIconUrl()" @click.stop="changeExpandStatus()"/><div class="parent-title" v-html="parentItem.text"></div></div></div><div class="child" v-if="isShowChildList()"><MenuTree :parentItem="item" v-for="(item, index) in parentItem.children" :currentLevel="currentLevel + 1":key="index" @onMenuTreeItemConfirm="onMenuTreeItemConfirm"></MenuTree></div></div>
</template><script>
export default {components: {MenuTree: () => import('./menu-tree.vue') // 引入自身作为子组件},props: {parentItem: {type: Object,default: {}},currentLevel: {type: Number,default: 1},},mounted() {},data() {return {treeMinUnitIconUrl: require('@/assets/images/icon-file.svg'),treeFoldedIconUrl: require('@/assets/images/icon-to-fold.svg'),treeExpandedIconUrl: require('@/assets/images/icon-to-expand.svg'),}},watch: {},methods: {isShowChildList() {return this.parentItem.expanded;},changeExpandStatus() {console.log("this.parentItem.childQty = " + this.parentItem.childQty);if (this.parentItem.childQty && this.parentItem.childQty > 0) {this.parentItem.expanded = !this.parentItem.expanded;}},getParentIconUrl() {if (this.currentLevel == 1) {return this.treeMinUnitIconUrl;}if (!this.parentItem.childQty || this.parentItem.childQty == 0) {return this.treeMinUnitIconUrl;}return this.parentItem.expanded ? this.treeFoldedIconUrl : this.treeExpandedIconUrl;},onParentClick(item) {if (this.currentLevel > 1) {item.currentLevel = this.currentLevel;}this.$emit("onMenuTreeItemConfirm", item);},onMenuTreeItemConfirm(item) {this.onParentClick(item);},},
}
</script><style scoped>
.root {width: 100%;min-height: 48px;display: flex;flex-direction: column;align-items: center;
}.parent {min-height: 48px;width: 100%;display: flex;flex-direction: row;align-items: center;
}.parent-rectangle {min-height: 48px;
}.parent-right {min-height: 48px;min-width: 140px;display: flex;flex-direction: row;align-items: center;
}.parent-icon {width: 24px;height: 24px;
}.parent-title {width: calc(100% - 24px - 8px);min-height: 16px;text-align: left;line-height: 16px;font-size: 14px;margin-left: 8px;
}.child {width: 100%;display: flex;flex-direction: column;align-items: center;
}
</style>

4、使用方法如下:

<template><div class="root"><van-popup class="popup" v-model="showMenuTreePop" round position="bottom"><div class="popup-title">请选择行政区划</div><div style="height: 60vh; width: 100%; overflow-y: scroll;"><MenuTree :parentItem="rootItem" :currentLevel="1" @onMenuTreeItemConfirm="onMenuTreeItemConfirm"></MenuTree></div><div class="table-bottom"><div class="table-bottom-btn color-green" @click="showMenuTreePop = false">取消</div></div></van-popup></div>
</template><script>
import MenuTree from '@/components/menu-tree.vue';
export default {components: { MenuTree },data() {return {rootItem: {},showMenuTreePop: false,}},methods: {loadMenutreeDataList() {// 通过网络请求获取数据列表 resconsole.log("res = ", res);this.$set(this.rootItem, "children", res);this.$set(this.rootItem, "text", "行政区划");this.$set(this.rootItem, "expanded", true);this.$set(this.rootItem, "childQty", res ? res.length : 0);this.showMenuTreePop = true;// 打开弹窗},onMenuTreeItemConfirm(clickedItem) {// clickedItem 就是点击选中的数据项, 其 currentLevel 属性值就是其所处层级,如果层级是1,则表示点击的是根节点this.showMenuTreePop = false;// 关闭弹窗},}
}
</script><style scoped>
.root {width: 100%;height: 100vh;
}.popup {width: 100%;background: #FFFFFF;border-radius: 16px;
}.table-bottom {width: 100%;height: 71px;display: flex;flex-direction: row;align-items: center;border-top: solid 1px #E8E8E8;
}.table-bottom-btn {min-width: 50px;height: 44px;flex: 1;color: #FFFFFF;font-size: 12px;line-height: 44px;border-radius: 22px;margin-left: 3%;margin-right: 3%;font-family: PingFangSC-Regular;font-weight: 400;text-align: center;
}.color-green {color: #FFFFFF;background-color: #2DA541;
}
</style>

5、插件中使用到的资源文件如下:

1、icon-file.svg<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1716600220842" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="19100" xmlns:xlink="http://www.w3.org/1999/xlink" width="48" height="48"><path d="M815.104 69.632q27.648 25.6 44.032 42.496t25.088 28.672 10.752 19.968 2.048 14.336l0 16.384-151.552 0q-10.24 0-17.92-7.68t-12.8-17.92-7.68-20.992-2.56-16.896l0-126.976 3.072 0q8.192 0 16.896 2.56t19.968 9.728 28.16 20.48 42.496 35.84zM640 129.024q0 20.48 6.144 42.496t19.456 40.96 33.792 31.232 48.128 12.288l149.504 0 0 577.536q0 29.696-11.776 53.248t-31.232 39.936-43.008 25.6-46.08 9.216l-503.808 0q-19.456 0-42.496-11.264t-43.008-29.696-33.28-41.984-13.312-49.152l0-696.32q0-21.504 9.728-44.544t26.624-42.496 38.4-32.256 45.056-12.8l391.168 0 0 128zM704.512 768q26.624 0 45.056-18.944t18.432-45.568-18.432-45.056-45.056-18.432l-384 0q-26.624 0-45.056 18.432t-18.432 45.056 18.432 45.568 45.056 18.944l384 0zM768 448.512q0-26.624-18.432-45.568t-45.056-18.944l-384 0q-26.624 0-45.056 18.944t-18.432 45.568 18.432 45.056 45.056 18.432l384 0q26.624 0 45.056-18.432t18.432-45.056z" p-id="19101" fill="#1296db"></path></svg>2、icon-to-expand.svg<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1716600138280" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5120" xmlns:xlink="http://www.w3.org/1999/xlink" width="48" height="48"><path d="M880 112a32 32 0 0 1 32 32v736a32 32 0 0 1-32 32H144a32 32 0 0 1-32-32V144a32 32 0 0 1 32-32z m-40 72H184v656h656V184zM536 320c4.416 0 8 3.584 8 8V480h152c4.416 0 8 3.584 8 8v48a8 8 0 0 1-8 8H544v152a8 8 0 0 1-8 8h-48a8 8 0 0 1-8-8V544H328A8 8 0 0 1 320 536v-48c0-4.416 3.584-8 8-8H480V328c0-4.416 3.584-8 8-8z" fill="#1296db" fill-opacity=".65" p-id="5121"></path></svg>3、icon-to-fold.svg<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1716600168259" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="18002" xmlns:xlink="http://www.w3.org/1999/xlink" width="48" height="48"><path d="M880 112a32 32 0 0 1 32 32v736a32 32 0 0 1-32 32H144a32 32 0 0 1-32-32V144a32 32 0 0 1 32-32z m-40 72H184v656h656V184zM696 480c4.416 0 8 3.584 8 8v48a8 8 0 0 1-8 8h-368A8 8 0 0 1 320 536v-48c0-4.416 3.584-8 8-8z" fill="#1296db" fill-opacity=".65" p-id="18003"></path></svg>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.pswp.cn/bicheng/83570.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

洛谷P12610 ——[CCC 2025 Junior] Donut Shop

题目背景 Score: 15. 题目描述 The owner of a donut shop spends the day baking and selling donuts. Given the events that happen over the course of the day, your job is to determine the number of donuts remaining when the shop closes. 输入格式 The first …

数据挖掘顶刊《IEEE Transactions on Knowledge and Data Engineering》2025年5月研究热点都有些什么?

本推文对2025年5月出版的数据挖掘领域国际顶级期刊《IEEE Transactions on Knowledge and Data Engineering》进行了分析&#xff0c;对收录的62篇论文的关键词与研究主题进行了汇总&#xff0c;并对其中的研究热点进行了深入分析&#xff0c;希望能为相关领域的研究人员提供有…

华为OD机试真题——最小的调整次数/特异性双端队列(2025B卷:100分)Java/python/JavaScript/C++/C语言/GO六种最佳实现

2025 B卷 100分 题型 本文涵盖详细的问题分析、解题思路、代码实现、代码详解、测试用例以及综合分析; 并提供Java、python、JavaScript、C++、C语言、GO六种语言的最佳实现方式! 2025华为OD真题目录+全流程解析/备考攻略/经验分享 华为OD机试真题《最小的调整次数/特异性双端…

2024年ESWA SCI1区TOP,自适应学习灰狼算法ALGWO+无线传感器网络覆盖优化,深度解析+性能实测

目录 1.端午快乐2.摘要3.灰狼算法GWO原理4.改进策略5.结果展示6.参考文献7.代码获取8.读者交流 1.端午快乐 今天端午节&#xff0c;祝各位朋友端午安康&#xff0c;阖家平安&#xff01; 2.摘要 无线传感器网络&#xff08;WSNs&#xff09;是一种被广泛应用的新兴技术&…

ADI硬件笔试面试题型解析下

本专栏预计更新60期左右。当前第17期-ADI硬件. ADI其硬件工程师岗位的招聘流程通常包括笔试和多轮技术面试,考察领域涵盖模拟电路设计、数字电路、半导体器件和信号处理等。 本文通过分析平台上的信息,汇总了ADI硬件工程师的典型笔试和面试题型,并提供详细解析和备考建议,…

SpringCloud 分布式锁Redisson锁的重入性与看门狗机制 高并发 可重入

可重入 Redisson 的锁支持 可重入性&#xff0c;这意味着同一个线程在获取锁后&#xff0c;如果再次尝试获取该锁&#xff0c;它可以成功地获得锁&#xff0c;而不会被阻塞。 每次一个线程成功获取锁后&#xff0c;它的持有次数会增加。当线程再次获取该锁时&#xff0c;Redi…

Java 中 Redis 过期策略深度解析(含拓展-redis内存淘汰策略列举)

&#x1f91f;致敬读者 &#x1f7e9;感谢阅读&#x1f7e6;笑口常开&#x1f7ea;生日快乐⬛早点睡觉 &#x1f4d8;博主相关 &#x1f7e7;博主信息&#x1f7e8;博客首页&#x1f7eb;专栏推荐&#x1f7e5;活动信息 文章目录 Java 中 Redis 过期策略深度解析一、Redis 过…

Flutter - 原生交互 - 相机Camera - 01

环境 Flutter 3.29 macOS Sequoia 15.4.1 Xcode 16.3 集成 Flutter提供了camera插件来拍照和录视频&#xff0c;它提供了一系列可用的相机&#xff0c;并使用特定的相机展示相机预览、拍照、录视频。 添加依赖 camera: 提供使用设备相机模块的工具path_provider: 寻找存储图…

基于 Amazon Q Developer CLI 和 Amazon Bedrock Knowledge Bases 实现智能问答系统

1. 引言 传统企业通常将常见问题&#xff08;FAQ&#xff09;发布在网站上&#xff0c;方便客户自助查找信息。然而&#xff0c;随着生成式 AI 技术的迅速发展与商业渗透&#xff0c;这些企业正积极探索构建智能问答系统的新途径。这类系统不仅能显著提升客户体验&#xff0c;…

Go 为何天生适合云原生?

当前我们正处在 AI 时代&#xff0c;但是在基础架构领域&#xff0c;仍然处在云原生时代。云原生仍然是当前时代的风口之一。作为一个 Go 开发者&#xff0c;职业进阶的下一站就是学习云原生技术。作为 Go 开发者学习云原生技术有得天独厚的优势&#xff0c;这是因为 Go 天生适…

Mac查看MySQL版本的命令

通过 Homebrew 查看&#xff08;如果是用 Homebrew 安装的&#xff09; brew info mysql 会显示你安装的版本、路径等信息。 你的终端输出显示&#xff1a;你并没有安装 MySQL&#xff0c;只是查询了 brew 中的 MySQL 安装信息。我们一起来看下重点&#xff1a; &#x1f9fe…

Kafka ACK机制详解:数据可靠性与性能的权衡之道

在分布式消息系统中&#xff0c;消息确认机制是保障数据可靠性的关键。Apache Kafka 通过 ACK&#xff08;Acknowledgment&#xff09;机制 实现了灵活的数据确认策略&#xff0c;允许用户在 数据可靠性 和 系统性能 之间进行权衡。本文将深入解析 Kafka ACK 机制的工作原理、配…

FastMCP:构建 MCP 服务器和客户端的高效 Python 框架

在人工智能领域&#xff0c;模型上下文协议&#xff08;Model Context Protocol&#xff0c;简称 MCP&#xff09;作为一种标准化的协议&#xff0c;为大型语言模型&#xff08;LLM&#xff09;提供了丰富的上下文和工具支持。而 FastMCP 作为构建 MCP 服务器和客户端的 Python…

动态库导出符号与extern “C“

1. windows下动态库导出符号 根据C/C语法规则&#xff0c;函数声明中的修饰符&#xff08;如__declspec(dllexport)&#xff09;可以放在返回类型之前或返回类型之后、函数名之前。这两种方式在功能上是等价的&#xff0c;编译器会以相同的方式处理。 __declspec(dllexport) …

Linux(9)——进程(控制篇——下)

目录 三、进程等待 1&#xff09;进程等待的必要性 2&#xff09;获取子进程的status 3&#xff09;进程的等待方法 wait方法 waitpid方法 多进程创建以及等待的代码模型 非阻塞的轮训检测 四、进程程序替换 1&#xff09;替换原理 2&#xff09;替换函数 3&…

Datatable和实体集合互转

1.使用已废弃的 JavaScriptSerializer&#xff0c;且反序列化为弱类型 ArrayList。可用但不推荐。 using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Linq; using System.Reflection; using System.Web; using Sy…

阿里云服务器ECS详解:云服务器是什么,云服务器优势和应用场景及参考

云服务器ECS是阿里云众多云产品中&#xff0c;最受用户关注的产品&#xff0c;阿里云服务器提供多样化的计算能力&#xff0c;支持x86、Arm架构&#xff0c;涵盖CPU、GPU等多种服务器类型&#xff0c;满足各种用户需求。其便捷易用特性包括分钟级交付、通用API和性能监控框架&a…

【Oracle】游标

个人主页&#xff1a;Guiat 归属专栏&#xff1a;Oracle 文章目录 1. 游标基础概述1.1 游标的概念与作用1.2 游标的生命周期1.3 游标的分类 2. 显式游标2.1 显式游标的基本语法2.1.1 声明游标2.1.2 带参数的游标 2.2 游标的基本操作2.2.1 完整的游标操作示例 2.3 游标属性2.3.1…

pikachu靶场通关笔记11 XSS关卡07-XSS之关键字过滤绕过(三种方法渗透)

目录 一、源码分析 1、进入靶场 2、代码审计 3、攻击思路 二、渗透实战 1、探测过滤信息 2、注入Payload1 3、注入Payload2 4、注入Payload3 本系列为通过《pikachu靶场通关笔记》的XSS关卡(共10关&#xff09;渗透集合&#xff0c;通过对XSS关卡源码的代码审计找到安…

XML 元素:基础、应用与优化

XML 元素:基础、应用与优化 引言 XML(可扩展标记语言)作为一种数据交换的标准格式,广泛应用于互联网数据交换、数据存储等领域。XML 元素是 XML 文档的核心组成部分,本文将深入探讨 XML 元素的概念、特性、应用以及优化方法。 一、XML 元素概述 1.1 XML 元素的定义 X…