.router-link-active {
color: #f40;
}
.router-link-exact-active {
border-bottom: 1px solid #f40;
}
const router = createRouter({
// ...
linkActiveClass : "nav-color",
linkExactActiveClass : "exact-nav-color",
})
router.options = {
linkActiveClass: "nav-color",
linkExactActiveClass: "exact-nav-color",
};
router.options.linkActiveClass = "nav-color"
router.options.linkExactActiveClass = "exact-nav-color"
<RouterLink activeClass="btm" exactActiveClass="color" to="/home">home</RouterLink> <RouterLink active-class="btm" exact-active-class="color" to="/mine">mine</RouterLink>
.btm {
color: #f40;
}
.color {
border-bottom: 1px solid #f40;
}
const router = createRouter({
history: createWebHistory(),
routes:[
//...
],
linkActiveClass: "nav-color",
linkExactActiveClass: "exact-nav-color",
});
.nav-color {
color: var(--main-color);
}
.exact-nav-color {
color: var(--main-color);
}
const nav = ref([
{ id: 0, title: '首页', path: '/', icon: 'icon-home1' },
{ id: 1, title: '菜单', path: '/menu', icon: 'icon-coffee-cup' },
{ id: 2, title: '电商', path: '/mall', icon: 'icon-Bag-' },
{ id: 3, title: '会员卡', path: '/membership', icon: 'icon-membership_code' },
{ id: 4, title: '我的', path: '/mine', icon: 'icon-rudolfdeer' }
])
<div class="app-nav">
<RouterLink class="nav-item" v-for="(item, ind) in nav" :to="item.path" :key="item.id" replace>
<span class="iconfont" :class="item.icon"></span>
<div>{{ item.title }}</div>
</RouterLink>
</div>
{
path: "/menu",
name: "menu",
redirect: "/menu/goods",
component: () => import("@/views/MenuView.vue"),
meta: { showNav: true, title: "菜单" },
children: [
{
path: "goods",
name: "goods",
component: () => import("@/components/Goods.vue"),
meta: { title: "菜单-商品列表" },
},
{
path: "vip",
name: "vip",
component: () => import("@/components/Vip.vue"),
meta: { title: "菜单-会员卡" },
},
{
path: "rank",
name: "rank",
component: () => import("@/components/Rank.vue"),
meta: { title: "菜单-年度封神榜" },
},
{
path: "favorite",
name: "favorite",
component: () => import("@/components/Favorite.vue"),
meta: { title: "菜单-我的常点" },
},
],
}
const tabs = [
{ ind: 0, title: '经典菜单', path: '/menu/goods', keyword: 'classic' },
{ ind: 1, title: '会员卡', path: '/menu/vip', keyword: 'member' },
{ ind: 2, title: '年度封神榜', path: '/menu/rank', keyword: 'rank' },
{ ind: 3, title: '我的常点', path: '/menu/favorite', keyword: 'favor' },
]
<div class="links">
<RouterLink class="link" v-for="(item, ind) in tabs" :key="item.id" :to="item.path">
{{ item.title }}
</RouterLink>
</div>
<div class="sub-view">
<RouterView />
</div>
.link {
position: relative;
}
.exact-nav-color::after {
content: '';
position: absolute;
left: 50%;
bottom: 0;
transform: translateX(-50%);
width: 60%;
height: 4px;
background-color: var(--main-color);
}
. <RouterLink> 路由样式设置
. 全局应用路由样式和单独设置路由样式
. 标签属性类适合单独定制
. 路由属性类适合全局定制,也可以在相应的组件中,通过覆盖的方式单独定制