解决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>
相关推荐
nibabaoo3 天前
前端开发攻略---Vue3项目中实现指定区域的打印预览与 PDF 导出功能
vue3·js·打印预览pdf
nibabaoo3 天前
前端开发攻略---在 Vue 3 项目中使用 vue-i18n 实现国际化多语言
前端·javascript·国际化·i18n·vue3
浩宇软件开发4 天前
springBoot+Vue中华诗词学习后台管理系统
vue.js·spring boot·axios·element-plus·router
沙振宇4 天前
【Web】使用Vue3+PlayCanvas开发3D游戏(四)3D障碍物躲避游戏2-模型加载
游戏·3d·vue3·vite·playcanvas
SuperEugene5 天前
Vue3 中后台实战:VXE Table 从基础表格到复杂业务表格全攻略 | Vue生态精选篇
前端·vue.js·状态模式·vue3·vxetable
p5l2m9n4o6q5 天前
Vue3后台管理系统布局实战:从零搭建Element Plus左右布局(含Pinia状态管理)
vue3·pinia·element plus·viewui·后台管理系统
梵得儿SHI5 天前
Vue3 生态工具实战进阶:API 请求封装 + 样式解决方案全攻略(Axios/Sass/CSS Modules)
前端·css·vue3·sass·api请求·样式解决方案·组合式api管理
行者-全栈开发6 天前
43 篇系统实战:uni-app 从入门到架构师成长之路
前端·typescript·uni-app·vue3·最佳实践·企业级架构
沙振宇6 天前
【Web】使用Vue3+PlayCanvas开发3D游戏(二)3D 地图自由巡视闯关游戏
游戏·3d·vue3·playcanvas
沙振宇6 天前
【Web】使用Vue3+PlayCanvas开发3D游戏(一)3D 立方体交互式游戏
游戏·3d·vue·vue3·playcanvas