解决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>
相关推荐
沛沛老爹4 天前
Vue3+TS实战:基于策略模式的前端动态脱敏UI组件设计与实现
前端·ui·vue3·数据安全·策略模式·动态渲染·前端脱敏
gsls2008085 天前
vue3学习笔记
笔记·vue3
平头也疯狂7 天前
RuoYi Office 全景介绍:一个平台管好整个企业
微服务·vue3·springboot·crm·oa·企业管理系统
weixin79893765432...8 天前
vue3 系统的梳理
vue.js·vue3
利刃大大9 天前
【Vue】Element-Plus快速入门 && Form && Card && Table && Tree && Dialog && Menu
前端·javascript·vue.js·element-plus
是梦终空10 天前
计算机毕业设计264—基于Springboot+Vue3+协同过滤的房屋租赁管理系统(源代码+数据库+万字论文+设计文档)
spring boot·毕业设计·vue3·课程设计·毕业论文·协同过滤·房屋租赁管理系统
Irene199112 天前
通用消息组件 bug 修复及更好的实现是使用函数调用组件
vue3·函数调用·通用消息组件
Irene199113 天前
Vuex4:专为 Vue 3 设计,提供完整 TypeScript 支持
vue3·vuex4
无法长大13 天前
如何判断项目需不需要用、能不能用Tailwind CSS
前端·css·vue.js·elementui·vue3·tailwind css
cui_win14 天前
企业级中后台开源解决方案汇总
开源·vue3·ts