解决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>
相关推荐
SL-staff17 小时前
Vue3私有化AI白板落地实战|解决政企项目智能绘图合规难题(可直接复用源码)
人工智能·低代码·开源·vue3·白板·jvs规则引擎·jvs-draw
雨季mo浅忆17 小时前
Cursor快速实现上传Excel功能
前端·vue3·ai编程
ANnianStriver3 天前
PetLumina-AI 驱动的宠物生活管理平台
java·生活·vue3·springboot·ai编程·宠物·全栈开发
雨季mo浅忆4 天前
记录Vue3项目中的各类问题
前端·bug·vue3
八目蛛6 天前
八目蛛网络(免费工具网站导航)
css·vue.js·开源·vue3·html5·ai编程
颂love7 天前
Vue3基础入门
前端·学习·vue3
海市公约8 天前
Vue3组合式API中watch传值生命周期与自定义Hook实战
vue3·生命周期·watch·props·组件通信·defineexpose·自定义hook
海市公约9 天前
Vue3组合式API与响应式系统核心机制详解
vue3·computed·reactive·ref·响应式系统·composition api·script setup
菜鸟茜9 天前
Vue3 + Element Plus 省市区县级联cascader组件封装,支持 v-model 双向绑定 + 回显,可直接复用
element-plus·el-cascader
小茴香3539 天前
Vue3路由权限动态管理
前端·前端框架·vue3