当前位置: 首页 > news >正文

vue3+ant design vue动态实现级联菜单~

1、这里使用的是ant design vue 的TreeSelect 树选择来实现的。

<a-form-item name="staffDept" label="责任部门" labelAlign="left"><a-tree-selectv-model:value="formState.staffDept"show-search//允许在下拉框中添加搜索框style="width: 100%":dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"//设置下拉菜单的最大高度和溢出行为placeholder="请输入"allow-clear//显示清楚按钮tree-default-expand-all//默认展开所有树节点:tree-data="treeData"//将数据绑定在树形结构上/>
</a-form-item>import type { TreeSelectProps } from 'ant-design-vue';
import {getOrganizationChatrt} from '@/api/import';
const treeData = ref<TreeSelectProps['treeData']>([]);
const formState = ref({staffDept: '',
});
const handData = (array, level?) => {array.forEach((item, index) => {if (level === 0) {//获取一级菜单item.title = item.deptName;item.value = item.deptId;}if (item.nodeOfChildren != null) {//获取二级菜单item.children = [...item.nodeOfChildren];item.children.map((res) => {res.title = res.deptName;res.value = res.deptId;});handData(item.nodeOfChildren);//递归遍历,获取后续菜单如三级菜单}});treeData.value = array;
};
onMounted(() => {getOrganizationChatrt({}).then((res) => {console.log('测试数据', res);handData(res, 0);});
});
//假设这是后端返回的数据
[{"deptId": "00001","deptName": "营销中心","parentDeptId": "a00001","nodeOfChildren": [{"deptId": "000011","deptName": "网络管理部","parentDeptId": "00001","nodeOfChildren": [{"deptId": "0000111","deptName": "网络开发","parentDeptId": "000011","nodeOfChildren": null,"title": "网络开发","value": "001"},{"deptId": "0000112","deptName": "网络管理","parentDeptId": "000011","nodeOfChildren": null,"title": "网络管理","value": "002"}]},{"deptId": "000012","deptName": "市场营销部","parentDeptId": "00001","nodeOfChildren": null}]}
]

2、效果图

http://www.lryc.cn/news/436984.html

相关文章:

  • 软件可维护性因素例题
  • git的一些操作
  • opencv实战项目二十三:基于BEBLID描述符的特征点匹配实现表盘校正
  • 数据库是全表扫描是怎么扫描法?
  • 认准这10款人力资源系统,90%的企业都在用!
  • 2024年我的利基出版转型——新战略与重点解析
  • 【数据结构】双向链表专题
  • 大二上学期计划安排
  • HarmonyOS开发实战( Beta5.0)图片编辑实现马赛克效果详解
  • 【新书介绍】《JavaScript前端开发与实例教程(微课视频版)(第2版)》
  • 什么是GWAS全基因组关联分析?
  • k8s dashboard token 生成/获取
  • windows@openssh免密登陆配置@基于powershell快速配置脚本
  • 【深度学习】【图像分类】【OnnxRuntime】【Python】VggNet模型部署
  • 手写排班日历
  • SpringBoot多数据源配置
  • 影响画布微信小程序canvas及skyline和webview用户界面布局的关键流程
  • MATLAB图像处理
  • 【编程底层思考】性能监控和优化:JVM参数调优,诊断工具的使用等。JVM 调优和线上问题排查实战经验总结
  • 数据库的实施过程分析
  • 【Kubernetes】常见面试题汇总(十二)
  • 基于SpringBoot+Vue+MySQL的美术馆管理系统
  • golang面试
  • 基于"WT2605C的智能血压计:AI对话引领个性化健康管理新时代,健康守护随时在线
  • redis高级教程
  • prfm命令初探
  • AI大模型需要学什么?怎么学?从零基础入门大模型(保姆级),从这开始出发!
  • python自述3
  • Redis常见的数据结构
  • 批量插入insert到SQLServer数据库,BigDecimal精度丢失解决办法,不动代码,从驱动层面解决