Answer the question
In order to leave comments, you need to log in
How to make active class only on one menu item?
There is this code:
<template>
<ul class="sidenav app-sidenav open">
<li v-for="link in links" :key="link.url">
<router-link
:to="link.url"
class="waves-effect waves-orange pointer"
>
{{ link.title }}
</router-link>
</li>
</ul>
</template>
<script>
export default {
data: () => ({
links: [
{ title: "Счет", url: "/" },
{ title: "История", url: "/history" },
{ title: "Планирование", url: "/planning" },
{ title: "Новая запись", url: "/record" },
{ title: "Категории", url: "/categories" },
],
}),
};
</script>
Answer the question
In order to leave comments, you need to log in
Such a class already exists . If you need to style the link - use it .
UPD. Taken from the comments:
Is there a way to assign your own class?
computed: {
activeLink() {
return this.links.find(n => n.url === this.$route.path);
},
},
:class="{ active: activeLink === link }"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question