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

vue3从其他页面跳转页面头部组件菜单el-menu菜单高亮

主要代码

import { ref, onMounted, watch } from 'vue';
const activeIndex = ref("/");
const route = useRoute();onMounted(() => {updateActiveMenu();
});watch(() => route.path, updateActiveMenu);function updateActiveMenu() {// 根据路由更新activeMenu的值,使菜单高亮activeMenu.value = route.fullPath;
}

头部组件 

<template><divclass="header-container flex-center-center header-element-sty":class="isDefault ? 'default-sty' : 'change-sty'"id="subei1"@mouseenter="changeActive()"@mouseleave="removeActive()"><el-menu:default-active="activeIndex"class="el-menu"mode="horizontal":ellipsis="false"active-text-color="#74237e"menu-trigger="click"@select="handleSelect":unique-opened="true"><div class="header-logo" @click="toHome"></div><div class="flex-grow" /><el-sub-menu index="/brandNews" class="header-item"><template #title><span class="el-menu-item-txt">品牌动态</span></template><el-menu-item index="/brandNews?active=company_news">公司新闻</el-menu-item><el-menu-item index="/brandNews?active=media_coverage">媒体报道</el-menu-item><el-menu-item index="/brandNews?active=popular_science_course">科普教程</el-menu-item><el-menu-item index="/brandNews?active=popular_science_activity">科普活动</el-menu-item></el-sub-menu><el-menu-item class="el-menu-item-txt header-item" index="/?name=smartGym"><template #title><span class="el-menu-txt">室外智能健身房</span></template></el-menu-item><el-menu-item class="el-menu-item-txt header-item" index="/sportsCampus"><template #title><span class="el-menu-item-txt">智慧体育公园</span></template></el-menu-item><el-sub-menu class="header-item" index="/fitnessPlans"><template #title><span class="el-menu-item-txt">全民健身方案</span></template><el-menu-item index="/fitnessPlans?plan=smart_sports_campus">智慧体育公园</el-menu-item><el-menu-item index="/fitnessTrain?plan=intelligent_fitness_trail">智能健身步道</el-menu-item><el-menu-item index="/fitnessPath?plan=national_fitness_path">全民健身路径</el-menu-item><el-menu-item index="/fitnessCenter?plan=digital_fitness_center">数字健身中心</el-menu-item></el-sub-menu><el-sub-menu class="header-item" index="/match"><template #title><span class="el-menu-item-txt">智能赛事</span></template><el-menu-item index="/match?active=preview">活动预告</el-menu-item><el-menu-item index="/match?active=sign_up">参赛报名</el-menu-item><el-menu-item index="/match?active=review">赛事回顾</el-menu-item></el-sub-menu><el-menu-item class="el-menu-item-txt header-item"><aclass="menu-item-a"href="https://www.topsupport.cn/"target="_blank">TopSupport</a></el-menu-item><el-menu-item class="el-menu-item-txt header-item"><aclass="menu-item-a"href="https://www.topsupport.cn/"target="_blank">运动健康商城</a></el-menu-item><el-sub-menu class="header-item" index="/about"><template #title><span class="el-menu-item-txt">关于我们</span></template><el-menu-item index="/about?about=us">集团简介</el-menu-item><el-menu-item index="/customer?about=customer">客服中心</el-menu-item></el-sub-menu></el-menu></div>
</template>
<script lang="ts" setup>
import { ref, onMounted, onUnmounted,watch } from "vue";
const navBackgroundColor = ref("transparent");
const isDefault = ref(false);
const activeIndex = ref("/");
const route= useRoute();
const handleSelect = (key: string, keyPath: string[]) => {activeIndex.value = key;navigateTo(key, { external: true });//页面跳转
};// 根据路由更新activeIndex的值,使菜单高亮
function updateActiveMenu() {activeIndex.value = route.fullPath;
}
// 监听路由
watch(() => route.path, updateActiveMenu);const toHome = () => {activeIndex.value = "/";navigateTo("/");
};
const handleScroll=()=> {// window.innerHeightconst navHeight = 420; // 窗口高度if (window.scrollY >= navHeight) {isDefault.value = true;} else {isDefault.value = false;}
}
const changeActive=()=> {document.getElementById("subei1").classList.add("mouseenterSty");
}
const removeActive=()=>{document.getElementById("subei1").classList.add("mouseleaveSty");
}
onMounted(() => {window.addEventListener("scroll", handleScroll);updateActiveMenu();//使选中页面菜单高亮的方法
});onUnmounted(() => {window.removeEventListener("scroll", handleScroll);
});</script>
<style lang="scss" scoped>
.header-container {width: 100%;position: fixed;// border-bottom: 1px solid rgba(255,255,255,0.5);top: 0;z-index: 99;background: #ffffff;overflow: hidden;.left {img {height: 3rem;}}
}.el-menu {background-color: transparent;display: flex;align-items: center;justify-content: center;border-bottom: none !important;font-size: var(fs-content-normal);&-item {font-size: var(--fs-content-most);display: flex;justify-content: center;}&-item-txt {padding-left: 3rem;}img {width: 6.5rem;}
}
.flex-grow {flex-grow: 1;
}
.el-menu--popup-bottom-start .el-menu-item {display: flex;justify-content: center;
}:deep.el-menu-item {padding: 0;
}:deep.el-menu-item-txt {padding-left: 0;
}
:deep.el-menu:not(.el-menu--collapse) .el-sub-menu__title {padding: 0 1.5rem;
}
.el-menu-item-txt:hover {color: var(--color-priority) !important;background-color: transparent !important;
}
.el-menu--horizontal > .el-menu-item {border-bottom: none;text-decoration: none;
}.el-menu--horizontal > .el-menu-item:hover {color: var(--color-priority) !important;
}
:deep(.el-sub-menu__title) {font-size: var(--fs-content-most);
}// 导航样式
.header-item {padding: 0 1.5rem;
}
// 白底导航
.default-sty {background: #ffffff;.header-logo {width: 10.5rem;height: 2.81rem;background: url(/image/logo.png) no-repeat center center;background-size: 100% 100%;}
}
// 透明导航
.change-sty {background: linear-gradient(180deg, rgba(0, 0, 0, 0.3) 13%, rgba(0, 0, 0, 0));.header-logo {width: 10.5rem;height: 2.81rem;background: url(/image/logo_white.png) no-repeat center center;background-size: 100% 100%;}
}
.mouseenterSty {background: #ffffff;.header-logo {width: 10.5rem;height: 2.81rem;background: url(/image/logo.png) no-repeat center center;background-size: 100% 100%;}}</style>

其他页面跳转

<router-link class="menu-item-a" to="/brandNews?active=company_news">品牌动态</router-link>

相关文章:

vue3从其他页面跳转页面头部组件菜单el-menu菜单高亮

主要代码 import { ref, onMounted, watch } from vue; const activeIndex ref("/"); const route useRoute();onMounted(() > {updateActiveMenu(); });watch(() > route.path, updateActiveMenu);function updateActiveMenu() {// 根据路由更新activeMenu…...

python 条件循环语句

python 条件循环语句 一、条件控制语句1. Python3 条件控制2. if 语句3. if 嵌套4. match...case5. 注意&#xff1a; 二、循环控制语句1. Python3 循环语句2. while 循环3. 无限循环4. while 循环使用 else 语句5. 简单语句组6. for 语句7. for...else8. break 和 continue 语…...

CIM搭建实现发送消息的效果

目录 背景过程1、下载代码2、进行配置3、直接启动项目4、打开管理界面5、启动web客户端实例项目6、发送消息 项目使用总结 背景 公司项目有许多需要发送即时消息的场景&#xff0c;之前一直采用的是传统的websocket连接&#xff0c;它会存在掉线严重&#xff0c;不可重连&…...

C++第十三弹---内存管理(下)

✨个人主页&#xff1a; 熬夜学编程的小林 &#x1f497;系列专栏&#xff1a; 【C语言详解】 【数据结构详解】【C详解】 目录 1、operator new与operator delete函数 1.1、operator new与operator delete函数 2、new和delete的实现原理 2.1、内置类型 2.2、自定义类型 …...

Python爬虫学习完整版

一、什么是爬虫 网络爬虫&#xff0c;是一种按照一定规则&#xff0c;自动抓取互联网信息的程序或者脚本。由于互联网数据的多样性和资源的有限性&#xff0c;根据用户需求定向抓取相关网页并分析也成为如今主流的爬取策略。 1 爬虫可以做什么 你可以爬取网络上的的图片&#…...

JavaScript中的继承方式详解

Question JavaScript实现继承的方式&#xff1f; 包含原型链继承、构造函数继承、组合继承、原型式继承、寄生式继承、寄生组合式继承和ES6 类继承 JavaScript实现继承的方式 在JavaScript中&#xff0c;实现继承的方式多种多样&#xff0c;每种方式都有其优势和适用场景。以下…...

Git基础(23):Git分支合并实战保姆式流程

文章目录 前言准备正常分支合并1. 创建两个不冲突分支2. 将dev合并到test 冲突分支合并1. 制造分支冲突2. 冲突合并 前言 Git分支合并操作 准备 这里先在Gitee创建了一个空仓库&#xff0c;方便远程查看内容。 正常分支合并 1. 创建两个不冲突分支 &#xff08;1&#xf…...

为什么有些前端一直用 div 当按钮,而不是用 button?

1. HTML 中的 <div> 和 <button> 在了解为什么有些前端开发者更喜欢使用 <div> 作为按钮之前&#xff0c;让我们先来了解一下 <div> 和 <button> 标签在 HTML 中的作用和区别。 <div>&#xff1a;是 HTML 中的一个通用容器元素&#xff0…...

python实战之基础篇(一)

1. 注释 # coding utf-8 # 该注释放到文件第一行, 这个注释告诉python解释器该文件的编码集是UTF-82. 导入语句有三种形式 import <模块名> from <模块名> import <代码元素> from <模块名> import <代码元素> as <代码元素别名>3. 获取…...

第十四届蓝桥杯大赛软件赛省赛C/C++ 大学 B 组(补题)

文章目录 1 日期统计2 01串的熵3 冶炼金属4 飞机降落5 接龙数列6 岛屿个数7 子串简写8 整数删除9 景区导游10 砍树 前言&#xff1a;时隔一年&#xff0c;再次做这套题(去年参赛选手)&#xff0c;差点道心不稳T_T&#xff0c;故作此补题&#xff01; 1 日期统计 没写出来&…...

蓝桥杯刷题--python-32

4964. 子矩阵 - AcWing题库 from collections import deque n, m, a, b map(int, input().split()) mod 998244353 nums [] for _ in range(n): nums.append(list(map(int, input().split()))) rmin [[0 for i in range(m)] for i in range(n)] rmax [[0 for i in ran…...

单例模式如何保证实例的唯一性

前言 什么是单例模式 指一个类只有一个实例&#xff0c;且该类能自行创建这个实例的一种创建型设计模式。使用目的&#xff1a;确保在整个系统中只能出现类的一个实例&#xff0c;即一个类只有一个对象。对于频繁使用的对象&#xff0c;“忽略”创建时的开销。特点&#xff1a…...

IntelliJ IDE 插件开发 | (七)PSI 入门及实战(实现 MyBatis 插件的跳转功能)

系列文章 IntelliJ IDE 插件开发 |&#xff08;一&#xff09;快速入门IntelliJ IDE 插件开发 |&#xff08;二&#xff09;UI 界面与数据持久化IntelliJ IDE 插件开发 |&#xff08;三&#xff09;消息通知与事件监听IntelliJ IDE 插件开发 |&#xff08;四&#xff09;来查收…...

【教程】iOS如何抓取HTTP和HTTPS数据包经验分享

&#x1f4f1; 在日常的App开发和研发调研中&#xff0c;对各类App进行深入的研究分析时&#xff0c;我们需要借助专业的抓包应用来协助工作。本文将介绍如何使用iOS手机抓包工具来获取HTTP和HTTPS数据包&#xff0c;并推荐一款实用的抓包应用——克魔助手&#xff0c;希望能够…...

基于javaweb(springboot)汽车配件管理系统设计和实现以及文档报告

基于javaweb(springboot)汽车配件管理系统设计和实现以及文档报告 博主介绍&#xff1a;多年java开发经验&#xff0c;专注Java开发、定制、远程、文档编写指导等,csdn特邀作者、专注于Java技术领域 作者主页 央顺技术团队 Java毕设项目精品实战案例《1000套》 欢迎点赞 收藏 ⭐…...

Spring Cloud Gateway Server MVC

之前你如果要用spring cloud gateway &#xff0c;就必须是webflux 的&#xff0c;也就是必须是异步响应式编程。不能和spring mvc 一起使用。现在spring cloud 新出了一个可以不用webflux的gateway。 具体使用mvc的gateway步骤如下 普通的Eureka Client的项目 如果你只是想测…...

建立动态MGRE隧道的配置方法

目录 一、实验拓扑 1.1通用配置 1.1.1地址配置 1.1.2静态缺省指向R5&#xff0c;实现公网互通 1.1.3MGRE协议配置 1.1.4配置静态 二、Shortcut方式 三、Normal方式&#xff08;非shortcut&#xff09; 四、总结 一、实验拓扑 下面两种配置方法皆使用静态方式 1.1通用配…...

【MySQL】9. 内置函数

函数 1. 日期函数 获得年月日&#xff1a; mysql> select current_date(); ---------------- | current_date() | ---------------- | 2024-03-23 | ---------------- 1 row in set (0.00 sec)获得时分秒&#xff1a; mysql> select current_time(); ------------…...

芯片工程系列(5)2.5D 3D封装

0 英语缩写 硅通孔&#xff08;Through Silicon Via&#xff0c;TSV&#xff09;硅中介层&#xff08;Silicon Interposer&#xff09;物理气象沉淀法&#xff08;Physical Vapor Deposition&#xff0c;PVD&#xff09;DRIE、CVD、PVD、CMP等设备CoWoS&#xff08;Chip on Wa…...

KubeSphere简单介绍及安装使用

KubeSphere 概述 官网地址&#xff1a;https://kubesphere.io/zh/ 什么是 kubesphere KubeSphere 是一个开源的多云容器管理平台&#xff0c;旨在简化企业级 k8s 集群的部署、管理和运维。它提供了一个可视化的管理界面&#xff0c;帮助用户更轻松地管理和监控 k8s 集群&…...

【JavaEE】-- HTTP

1. HTTP是什么&#xff1f; HTTP&#xff08;全称为"超文本传输协议"&#xff09;是一种应用非常广泛的应用层协议&#xff0c;HTTP是基于TCP协议的一种应用层协议。 应用层协议&#xff1a;是计算机网络协议栈中最高层的协议&#xff0c;它定义了运行在不同主机上…...

屋顶变身“发电站” ,中天合创屋面分布式光伏发电项目顺利并网!

5月28日&#xff0c;中天合创屋面分布式光伏发电项目顺利并网发电&#xff0c;该项目位于内蒙古自治区鄂尔多斯市乌审旗&#xff0c;项目利用中天合创聚乙烯、聚丙烯仓库屋面作为场地建设光伏电站&#xff0c;总装机容量为9.96MWp。 项目投运后&#xff0c;每年可节约标煤3670…...

Linux云原生安全:零信任架构与机密计算

Linux云原生安全&#xff1a;零信任架构与机密计算 构建坚不可摧的云原生防御体系 引言&#xff1a;云原生安全的范式革命 随着云原生技术的普及&#xff0c;安全边界正在从传统的网络边界向工作负载内部转移。Gartner预测&#xff0c;到2025年&#xff0c;零信任架构将成为超…...

现代密码学 | 椭圆曲线密码学—附py代码

Elliptic Curve Cryptography 椭圆曲线密码学&#xff08;ECC&#xff09;是一种基于有限域上椭圆曲线数学特性的公钥加密技术。其核心原理涉及椭圆曲线的代数性质、离散对数问题以及有限域上的运算。 椭圆曲线密码学是多种数字签名算法的基础&#xff0c;例如椭圆曲线数字签…...

IT供电系统绝缘监测及故障定位解决方案

随着新能源的快速发展&#xff0c;光伏电站、储能系统及充电设备已广泛应用于现代能源网络。在光伏领域&#xff0c;IT供电系统凭借其持续供电性好、安全性高等优势成为光伏首选&#xff0c;但在长期运行中&#xff0c;例如老化、潮湿、隐裂、机械损伤等问题会影响光伏板绝缘层…...

在鸿蒙HarmonyOS 5中使用DevEco Studio实现录音机应用

1. 项目配置与权限设置 1.1 配置module.json5 {"module": {"requestPermissions": [{"name": "ohos.permission.MICROPHONE","reason": "录音需要麦克风权限"},{"name": "ohos.permission.WRITE…...

力扣热题100 k个一组反转链表题解

题目: 代码: func reverseKGroup(head *ListNode, k int) *ListNode {cur : headfor i : 0; i < k; i {if cur nil {return head}cur cur.Next}newHead : reverse(head, cur)head.Next reverseKGroup(cur, k)return newHead }func reverse(start, end *ListNode) *ListN…...

探索Selenium:自动化测试的神奇钥匙

目录 一、Selenium 是什么1.1 定义与概念1.2 发展历程1.3 功能概述 二、Selenium 工作原理剖析2.1 架构组成2.2 工作流程2.3 通信机制 三、Selenium 的优势3.1 跨浏览器与平台支持3.2 丰富的语言支持3.3 强大的社区支持 四、Selenium 的应用场景4.1 Web 应用自动化测试4.2 数据…...

如何应对敏捷转型中的团队阻力

应对敏捷转型中的团队阻力需要明确沟通敏捷转型目的、提升团队参与感、提供充分的培训与支持、逐步推进敏捷实践、建立清晰的奖励和反馈机制。其中&#xff0c;明确沟通敏捷转型目的尤为关键&#xff0c;团队成员只有清晰理解转型背后的原因和利益&#xff0c;才能降低对变化的…...

永磁同步电机无速度算法--基于卡尔曼滤波器的滑模观测器

一、原理介绍 传统滑模观测器采用如下结构&#xff1a; 传统SMO中LPF会带来相位延迟和幅值衰减&#xff0c;并且需要额外的相位补偿。 采用扩展卡尔曼滤波器代替常用低通滤波器(LPF)&#xff0c;可以去除高次谐波&#xff0c;并且不用相位补偿就可以获得一个误差较小的转子位…...