vue-router active-class 进入当前菜单的样式
App.vue
<template> <div id="nav"> <!-- 导航 --> <router-link to="/" active-class="current">Home</router-link> | <router-link to="/about" active-class="current">About</router-link> | <router-link to="/test1_bak">Test1_bak</router-link> | <router-link to="/test1">Test1</router-link> | <router-link to="/test2">Test2</router-link> </div> <!-- 路由出口 --> <router-view/> </template> <style> #app { font-family: Avenir, Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-align: center; color: #2c3e50; } #nav { padding: 10px; background-color: lightskyblue; } #nav a { font-weight: bold; color: #2c3e50; } /* 默认选中样式类 */ #nav a.router-link-exact-active { color:orangered; } .current{ font-size: 24px; font-weight: bolder; } </style>
index.js
const router = createRouter({
history: createWebHashHistory(),
linkActiveClass:'current',
routes
})