I have a dynamic menu that comes from a REST API
.
My problem is: Today when I access some page, all the menus are closed. I wanted it when I entered for example a 3rd level page, the menu would open where the user is, for him to locate.
Home
For my ul
open, I need to put the collapse in
class. I have made the condition of :class
in my tag a
and it works, should I use it in condition to open my ul
?
Thank you!
Menu.vue :
<template>
<li v-for="item in Menu">
<router-link :to="{ name: item.Rota }" tag="a" :class="{ 'active': $route.name === item.Rota }">
{{item.Nome}}
</router-link>
<ul class="nav nav-second-level" v-if="item.SubMenu != null">
<li v-for="SecondItem in item.SubMenu">
<router-link :to="{ name: SecondItem.Rota }" tag="a" :class="{ 'active': $route.name === SecondItem.Rota }">
{{SecondItem.Nome}}
</router-link>
<ul class="nav nav-third-level" v-if="SecondItem.MenuItem != null">
<li v-for="ThirdItem in SecondItem.MenuItem">
<router-link :to="{ name: ThirdItem.Rota }" tag="a" :class="{ 'active': $route.name === ThirdItem.Rota }">
{{ThirdItem.Nome}}
</router-link>
</li>
</ul>
</li>
</ul>
</li>
</template>
<script>
import axios from 'axios'
export default {
data: () => ({
Menu: []
}),
created() {
let Data = [{
"Nome": "Produtos",
"MenuItem": [{
"Nome": "Catalogos de Produtos",
"Rota": "Produtos"
}]
},
{
"Nome": "Menu Teste",
"MenuItem": [{
"Nome": "Menu Teste Nível 3",
"MenuItem": [{
"Nome": "Página teste 3",
"Rota": "PagTesteTres"
}]
}]
}
]
this.Menu = Data;
}
}
</script>