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

自定义 el-menu

使用的工具:vue2 + element-ui 

<!DOCTYPE html>
<html><head><link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css"><style>.el-menu--horizontal {border-bottom: none !important;}.el-menu--horizontal .el-menu-item {height: 40px;line-height: 40px;}.el-menu--horizontal>.el-submenu .el-submenu__title {height: 40px;line-height: 40px;}.el-icon-arrow-down {display: none;}.el-submenu__title {padding: 0;}.is-active .el-submenu__title {border-bottom: none !important;color: #fff !important;}.is-active {background-color: #d3d4d6;}</style>
</head><body><div id="app"><div><el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal"><el-submenu v-for="(item, index) in menuItems" :key="index" :index="item.index"><template slot="title"><el-menu-item style="border-right: 1px solid #bfbfbf;content: '';">{{ item.name }}</el-menu-item></template><el-menu-item v-for="(subItem, subIndex) in item.subItems" :key="subIndex"@click="handleClick(item,subItem)" :index="item.index + '-' + 0">{{ subItem.name }}</el-menu-item></el-submenu></el-menu></div></div><script src="https://cdn.jsdelivr.net/npm/vue@2"></script><script src="https://unpkg.com/element-ui/lib/index.js"></script><script>new Vue({el: '#app',data() {return {activeIndex: '0',menuItems: [{ name: '常用商品', index: '1', subItems: [{ name: '全部' }, { name: '中型犬1-3kg以下' }, { name: '狗狗美容' }] },{ name: '短毛猫洗护', index: '2', subItems: [{ name: '全部' }, { name: '小型犬3-6kg' }] },{ name: '长毛猫洗护', index: '3', subItems: [{ name: '全部' },] },{ name: '猫咪单项服务', index: '4', subItems: [{ name: '全部' }, { name: '狗狗洗澡1-3kg以下' }] }],originalNames: {}};},created() {const firstMenu = this.menuItems[0];this.activeIndex = firstMenu.index + '-' + 0;// 初始化时保存每个一级菜单的原始 name 值this.menuItems.forEach(item => {this.$set(this.originalNames, item.index, item.name);});},methods: {handleClick(item, subItem) {this.activeIndex = item.index + '-' + 0;this.menuItems.forEach(v => {if (item.index === v.index) {if (subItem.name == "全部") {item.name = this.originalNames[item.index];}else {v.name = subItem.name}}});},}});</script>
</body></html>

相关文章:

  • 计算机网络——应用层
  • 基于SpringBoot成绩管理系统设计与实现(源码+文档+部署讲解)
  • STM32 基本GPIO控制
  • 鸿蒙NEXT开发键盘工具类(ArkTs)
  • 基于linux 设置无线网卡Monitor模式 sniffer抓包
  • C++面向对象
  • PyTorch入门------卷积神经网络
  • 医院数据中心智能化数据上报与调数机制设计
  • 2025mathorcup妈妈杯数学建模挑战赛C题:汽车风阻预测,详细思路,模型,代码更新中
  • 汽车免拆诊断案例 | 2019款大众途观L车鼓风机偶尔不工作
  • 零基础上手Python数据分析 (17):[案例实战] 电商销售数据分析 - 从数据到洞察的全流程演练
  • 磁流变式汽车减振器创新设计与关键技术研究
  • 【C++指南】哈希驱动的封装:如何让unordered_map/set飞得更快更稳?【上】
  • FreeRTOS菜鸟入门(七)·创建任务·静态任务创建
  • 网页端调用本地应用打开本地文件(PDF、Word、excel、PPT)
  • 再读bert(Bidirectional Encoder Representations from Transformers)
  • 动手学深度学习:手语视频在NiN模型中的测试
  • 万物互联时代,AWS IoT Core如何构建企业级物联网中枢平台?
  • MCP系列之实践篇:搭建你的第一个MCP应用
  • DemoGen:用于数据高效视觉运动策略学习的合成演示生成
  • 经济日报:上海车展展现独特魅力
  • 美施压拉美国家选边站队,外交部:搞阵营对抗注定失败
  • 中越海警2025年第一次北部湾联合巡逻圆满结束
  • 中国驻英国大使郑泽光:中国需要世界,世界也需要中国
  • “两高”发布侵犯知产犯罪司法解释:降低部分犯罪入罪门槛
  • 海关总署:明确部分货物、物品不再按进出境特殊物品监管