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

ruoyi vue element 实现点击、返回首页收起已经展开的菜单栏

问题描述

ruoyi VUE菜单有一个BUG,当我们点击其它按钮或者首页的时候,已经展示的一级菜单是不会自动收缩的。这个问题也导致很多开发者把一级菜单都换成了二级菜单。

解决方案 

// src/layout/components/Sidebar/index.vue<template><div :class="{ 'has-logo': showLogo }":style="{ backgroundColor: settings.sideTheme === 'theme-dark' ? variables.menuBackground : variables.menuLightBackground }"><logo v-if="showLogo" :collapse="isCollapse" /><el-scrollbar :class="settings.sideTheme" wrap-class="scrollbar-wrapper"><el-menu ref="menu" @open="handleOpen" :default-active="activeMenu" :collapse="isCollapse":background-color="settings.sideTheme === 'theme-dark' ? variables.menuBackground : variables.menuLightBackground":text-color="settings.sideTheme === 'theme-dark' ? variables.menuColor : variables.menuLightColor":unique-opened="true" active-text-color="#fff" :collapse-transition="false" mode="vertical"><sidebar-item v-for="(route, index) in sidebarRouters" :key="route.path + index" :item="route":base-path="route.path" /></el-menu></el-scrollbar></div>
</template><script>
import { mapGetters, mapState } from "vuex";
import Logo from "./Logo";
import SidebarItem from "./SidebarItem";
import variables from "@/assets/styles/variables.scss";export default {components: { SidebarItem, Logo },data() {return {keyIndex: 0,};},watch: {$route(to, from) {this.handleOpen(from.path);if (this.$route.path === '/index') {this.$refs.menu.close(this.keyIndex);}}},methods: {handleOpen(key) {let index = key.split('/');this.keyIndex = `/${index[1]}`;}},computed: {...mapState(["settings"]),...mapGetters(["sidebarRouters", "sidebar"]),activeMenu() {const route = this.$route;const { meta, path } = route;// if set path, the sidebar will highlight the path you setif (meta.activeMenu) {return meta.activeMenu;}return path;},showLogo() {return this.$store.state.settings.sidebarLogo;},variables() {return variables;},isCollapse() {return !this.sidebar.opened;}}
};
</script>

http://www.dtcms.com/a/365482.html

相关文章:

  • CI/CD流水线驱动自动化流程深度解析:选型、竞品、成本与资源消耗
  • Java项目打包成EXE全攻略​
  • 企业内网安全守护全面指南:从基础防护到智能管理的一站式解决方案
  • vue3前端开发的基础教程——快速上手
  • BERT实战|推理与微调
  • 如何从PDF中高效提取表格数据
  • Top 10 Kali Linux Tools for Hacking 2025.2
  • Flutter + Web:深度解析双向通信的混合应用开发实践
  • 深入解析 MySQL 存储引擎架构
  • 智能制造——解读71页装备制造集团SCM集成计划体系顶层设计方案【附全文阅读】
  • 超低延迟RTSP播放器的技术挑战与跨平台实现之道
  • AWK文本处理工具
  • 【Python练习题】Python小白必练100题答案-第81-97题
  • 采暖系统误区汇总!80%家庭中招,这样用才省电又健康
  • 特斯拉“宏图4.0”计划定调AI革命,相关巨头入局人形机器人赛道竞速升级!
  • 做 DevOps 还在被动救火?这篇让你把监控玩成 “运维加速器”!
  • 【FastDDS】Layer DDS之Domain ( 03-DomainParticipantListener)
  • GEO服务商推荐:移山科技以划时代高精尖技术引领AI搜索优化新纪元
  • 淘宝京东拼多多爬虫实战:反爬对抗、避坑技巧与数据安全要点
  • 非力扣100原题
  • 力扣hot100:螺旋矩阵(边界压缩,方向模拟)(54)
  • 2 XSS
  • PLSQL导入excel数据的三种方法
  • GitHub 宕机自救指南技术文章大纲
  • 模板进阶
  • Python/JS/Go/Java同步学习(第二篇)四语言数据基本类型对照表: 老板让我统一系统数据类型?(附源码/截图/参数表/老板沉默术)
  • GitLab Milestones 深度解析:选型、竞品、成本与资源消耗
  • 本地Merge-github有新的远程提交与本地新修改
  • 创建消息队列,完成信息传输
  • 输电线路杆塔倾斜在线监测装置:技术解析与实际应用