解决Vue3 使用Element-Plus导航刷新active高亮消失

解决Vue3 使用Element-Plus导航刷新后active高亮消失的问题

启用路由模式会在激活导航时以 index 作为 path 进行路由跳转 使用 default-active 来设置加载时的激活项。

接下来打印一下选中项index和index路径,

刷新也是没有任何问题的,active不会消失,整体代码如下:

javascript 复制代码
<template>
    <div class="header">
        <el-menu
                :router="true"
                :default-active="route.path"
                class="el-menu-demo"
                mode="horizontal"
                background-color="#545c64"
                text-color="#fff"
                active-text-color="#ffd04b"
                @select="handleSelect"
        >
            <el-menu-item index="/">Home</el-menu-item>
            <el-menu-item index="/about">About</el-menu-item>
            <el-menu-item index="/news">News</el-menu-item>
            <el-menu-item index="/product">Product</el-menu-item>
        </el-menu>
    </div>
</template>
<script setup lang="ts">
import {useRoute} from "vue-router";
const route=useRoute()
const handleSelect = (key: string, keyPath: string[]) => {
    console.log(key, keyPath)
}
</script>
相关推荐
码视野9 小时前
基于 Vue3 + Element Plus 的【智慧新能源汽车充电桩运维调度与分时共享租赁系统】设计与实现(附完整源码与PRD)
运维·人工智能·汽车·vue3
码视野15 小时前
基于 Vue3 + Element Plus 的【基于物联网的智慧居家养老健康关怀与紧急医疗呼叫系统】设计与实现(附完整源码与PRD)
人工智能·物联网·vue3
码视野1 天前
基于 Vue3 + Element Plus 的【基于物联网与深度学习的智慧工业园区能耗监测与光储充一体化微电网协同调度系统】设计与实现(附完整源码与PRD)
前端·人工智能·深度学习·物联网·vue3
码视野1 天前
基于 Vue3 + Element Plus 的【企业级 AI 智能体工作流与私有知识库 (RAG) 协同平台】设计与实现(附完整源码与PRD)
人工智能·vue3
筱璦2 天前
PHP+ VUE3机构级股票分仓管理交易系统源码可出
开发语言·php·vue3·量化·股票分仓
RuoyiOffice5 天前
SpringBoot3+Vue3 代码生成器深拆:元数据 IR、模板编译与安全同步
spring boot·vue3·mybatis plus·代码生成器·spring boot 3·velocity·元数据驱动
sir.山5 天前
在 Vue 3 项目中使用 Mock 数据
前端·vue.js·vue3·vite
盛夏绽放8 天前
Proxy与Reflect详解(二):进阶篇——手写Vue3响应式系统
ui·vue3·proxy
RuoyiOffice8 天前
抓包还能看到密码?Vue3 + Spring Boot 3 接口 AES/RSA 加解密(@ApiEncrypt)全链路实战
spring boot·vue3·aes·rsa·接口安全·spring boot 3·apiencrypt
RuoyiOffice10 天前
SpringBoot3+Vue3 接口访问日志实战:@ApiAccessLog 慢接口、参数脱敏与 OperateLog 如何分工
spring boot·vue3·traceid·spring boot 3·访问日志·apiaccesslog·操作日志