P粉9605255832023-08-30 18:38:25
If you use vue-router
and its <router-link>
components, you don't need to manage this yourself :)
This component will apply a special CSS class to the current active link. By default, the CSS class is router-link-active
.
<style> /* 样式化当前活动链接 */ .router-link-active { background-color: blue; } </style>
Documentation: https://router.vuejs.org/api/#active-class
P粉3950561962023-08-30 10:19:08
Please note that classes in Nuxt are actually
nuxt-link-active
nuxt-link-exact-active
Here is an example: https://nuxtjs.org/examples/routing-active-links-classes
This can be changed via configuration as follows: https://nuxtjs.org/docs/2.x/configuration-glossary/configuration-router#linkactiveclass