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

递归element-ui el-menu 实现无限级子菜单

recursionMenu.vue

<template><!-- 有子菜单------------------------------------------><el-submenuv-if="(item.children || []).length":popper-class="popper_class":show-timeout="show_timeout":hide-timeout="hide_timeout":key="item.path || item.label":index="item.path || item.label":divide="item.divide"><template slot="title"><!-- 主菜单图标 --><i :class="item.icon" :style="item.style" /><!-- 主菜单文字 --><span :style="item.style">{{ item.label }}</span><el-badgev-if="item.badge":is-dot="!item.badge.value":value="item.badge.value":type="item.badge ? item.badge.type : `danger`"/></template><recursionMenuv-for="(item, i) in item.children":key="item.path || item.label":data="{item,show_timeout: show_timeout,hide_timeout: hide_timeout,popper_class: popper_class,}"/></el-submenu><!-- 没有子菜单------------------------------------------><el-menu-itemv-else:key="`leaf-${item.path || item.label}`":index="item.path || item.label":divide="item.divide"><!-- 主菜单图标 --><i :class="item.icon" :style="item.style" /><!-- 主菜单文字 --><span :style="item.style">{{ item.label }}</span><el-badgev-if="item.badge":is-dot="!item.badge.value":value="item.badge.value":type="item.badge ? item.badge.type : `danger`"/></el-menu-item>
</template>
<script>
export default {name: `recursionMenu`,components: {},data() {return {item: {},popper_class: ``,show_timeout: 300,hide_timeout: 300,};},props: ["data"],computed: {},watch: {data: {handler(newValue, oldValue) {// console.log(`深度监听${this.$options.name}:`, newValue, oldValue);if (Object.keys(newValue || {}).length) {this.form = JSON.parse(JSON.stringify(newValue));this.$g.convertForm2ComponentParam(`item`, this);this.$g.convertForm2ComponentParam(`popper_class`, this);this.$g.convertForm2ComponentParam(`show_timeout`, this);this.$g.convertForm2ComponentParam(`hide_timeout`, this);}},deep: true, //深度监听immediate: true, //立即执行},},created() {},mounted() {// 将该行代码放到能够顺利执行的地方就可以,本示例中放到了mounted中// 由于这种错误只发生在template下只有一个el-submenu这种情况,因此this.$children[0]就是该el-submenuthis.$children[0].$parent = this.$parent;},beforeDestroy() {},methods: {},
};
</script>
<style lang="scss" scoped>
.recursionMenu {
}
</style>

demo

<template><div :class="$options.name"><el-menu:class="$options.name":collapse="collapse":default-active="default_active":default-openeds="default_openeds":mode="mode"@select="select"><recursionMenuv-for="(item, i) in menu":key="i":data="{item,show_timeout: show_timeout,hide_timeout: hide_timeout,popper_class: `admin_v2-top-submenu${collapse ? `-collapse` : ``}`,}"/></el-menu></div>
</template>
<script>
import recursionMenu from "@/vue/admin/recursionMenu";
export default {name: `topMenu`,components: { recursionMenu },data() {return {collapse: null,default_active: null,default_openeds: [], //默认展开的菜单index数组menu: [],mode: `horizontal`,select: null,show_timeout: 300,hide_timeout: 300,};},props: ["data"],computed: {},watch: {data: {handler(newValue, oldValue) {// console.log(`深度监听${this.$options.name}:`, newValue, oldValue);if (Object.keys(newValue || {}).length) {let select = newValue.select;this.select = select;delete newValue.select;this.form = JSON.parse(JSON.stringify(newValue));this.$g.convertForm2ComponentParam(`isSubMenu`, this);this.$g.convertForm2ComponentParam(`collapse`, this);this.$g.convertForm2ComponentParam(`default_active`, this);this.$g.convertForm2ComponentParam(`default_openeds`, this);this.$g.convertForm2ComponentParam(`menu`, this);this.$g.convertForm2ComponentParam(`mode`, this);this.$g.convertForm2ComponentParam(`show_timeout`, this);this.$g.convertForm2ComponentParam(`hide_timeout`, this);}},deep: true, //深度监听immediate: true, //立即执行},navList: {handler(newValue, oldValue) {//console.log(`深度监听${this.$options.name}:`, newValue, oldValue);if (Object.keys(newValue || {}).length) {this.collapse_navList = [{label: `菜单`,icon: "el-icon-menu",//   ID: "MENU-ROOT",// "PID": "SRManagePermissions",// "leaf": false,children: this.navList,},];}},deep: true, //深度监听immediate: true, //立即执行},},created() {},mounted() {},beforeDestroy() {},methods: {},
};
</script>
<style lang="scss" scoped>
.topMenu {>>> .el-menu {background-color: transparent;$menu-height: 50px;.el-icon-menu {color: white;}$active-background: radial-gradient(100% 80% at 50% 100%, #ffffff66, transparent 50%);.el-menu-item,.el-submenu__title {height: $menu-height;line-height: revert;display: flex;justify-content: center;align-items: center;padding: 0 10px;color: white !important;border-bottom: none !important;transition: none;// 选中菜单、聚焦菜单、移入菜单&.is-active,&:focus,&:hover {background: $active-background;}}// 有子菜单的.el-submenu__title {cursor: default;}.el-submenu {&.is-active {& > .el-submenu__title {background: $active-background;}}}.el-submenu__icon-arrow {display: none;}}
}
</style>
<style lang="scss">
.admin_v2-top-submenu,
.admin_v2-top-submenu-collapse {transition: none !important; //去掉下拉菜单动画transform: translateX(-10px);// 有子菜单的.el-submenu__title {cursor: default;}.el-menu-item {display: flex;justify-content: center;align-items: center;padding: 0 20px !important;transition: none;&.is-active {pointer-events: none;background-color: #409eff !important;color: white !important;}&:hover {background-color: #ecf5ff;color: #66b1ff !important;}}
}
.admin_v2-top-submenu-collapse {.el-menu-item {justify-content: flex-start;}.el-submenu {padding: 0 20px;.el-menu-item {min-width: revert;}.el-submenu__title {display: flex;align-items: center;padding: 0 !important;.el-submenu__icon-arrow {position: static;margin-top: revert;margin-left: 10px;}}&.is-active {background-color: #409eff;& > .el-submenu__title {background-color: transparent;& > * {color: white;}}}}
}
</style>

解决报错el-menu子菜单鼠标移入报“Maximum call stack size exceeded.“错误原因及解决方法-CSDN博客文章浏览阅读25次。【代码】el-menu子菜单鼠标移入报“Maximum call stack size exceeded.“错误原因及解决方法。 https://blog.csdn.net/qq_37860634/article/details/147758875


文章转载自:

http://YsceZAnl.rbyLq.cn
http://UpF1B5ss.rbyLq.cn
http://Uv0WyYJT.rbyLq.cn
http://aLQAESrc.rbyLq.cn
http://Vwzcbgb5.rbyLq.cn
http://o3Wj8RpC.rbyLq.cn
http://qSCTIrJ3.rbyLq.cn
http://Gq7leQ3D.rbyLq.cn
http://8zycSUx7.rbyLq.cn
http://ps7GjMFZ.rbyLq.cn
http://MdUCXPWw.rbyLq.cn
http://mfYbYCZv.rbyLq.cn
http://tdbUBHeZ.rbyLq.cn
http://ucsxrR8K.rbyLq.cn
http://WLS7y3sf.rbyLq.cn
http://b3hpuz8b.rbyLq.cn
http://fwMJvAV1.rbyLq.cn
http://HmgTf9qh.rbyLq.cn
http://wxsBnR4a.rbyLq.cn
http://6DVNA3wg.rbyLq.cn
http://hS6YCTk0.rbyLq.cn
http://jskj3ce3.rbyLq.cn
http://ca9uT1rm.rbyLq.cn
http://L8VzNolE.rbyLq.cn
http://MAXnJtns.rbyLq.cn
http://u9wXmDfx.rbyLq.cn
http://9wrHkxwb.rbyLq.cn
http://SVGY0IGI.rbyLq.cn
http://tQZK2nc6.rbyLq.cn
http://xt8Iu091.rbyLq.cn
http://www.dtcms.com/a/176071.html

相关文章:

  • Nginx 搭建支持多版本和前端路由的静态网站
  • 初始图形学(7)
  • C++并发编程完全指南:从基础到实践
  • 准确---Typora配置Gitee图床并实现自动图片上传
  • Windows环境下maven的安装与配置
  • 实践003-Gitlab CICD编译构建
  • 隐私计算技术及其在数据安全中的应用:守护数据隐私的新范式
  • python 闭包获取循环数据经典 bug
  • 滑动窗口——长度最小子数组
  • Go 并发错误处理利器:深入理解 errgroup
  • Kafka的消息保留策略是怎样的? (基于时间log.retention.hours或大小log.retention.bytes,可配置删除或压缩策略)
  • 【前端基础】7、CSS的字体属性(font相关)
  • 《Python星球日记》 第47天:聚类与KMeans
  • 学习笔记:黑马程序员JavaWeb开发教程(2025.3.30)
  • 项目模拟实现消息队列第二天
  • spring 事务实现原理
  • RabbitMq学习(第一天)
  • C++中的位运算符:与、或、异或详解
  • 阿里云2核2g安装nexus
  • shell脚本--2
  • 如何在大型项目中解决 VsCode 语言服务器崩溃的问题
  • 【shardingsphere分布式主键无效】
  • Kubernetes(k8s)学习笔记(八)--KubeSphere定制化安装
  • C 语言编码规范
  • Selenium使用指南
  • 21. LangChain金融领域:合同审查与风险预警自动化
  • 802.11s Mesh 组网框架流程
  • 排序算法——桶排序
  • 一个电平转换电路导致MCU/FPGA通讯波形失真的原因分析
  • 阿里云codeup以及本地gitclone+http