0
I have a dynamic menu that comes from a REST API
.
My problem is: Today when I access some page, all menus come closed. I wanted when I entered for example in a page 3° level, the menu opened according to where the user is, for him to locate.
To my ul
open, I need to put the class collapse in
. I made the condition of :class
on my tag a
and it works, should I use it on condition to open my ul
?
Thank you!
Menu.:
<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>
It would be interesting to put more code, just with that and it is difficult to help.
– Rafael Augusto
@Rafaelaugusto I put the entire Menu. this parameter "Route" is the name of the route.
– Jackson
If I access the Page Test 3 in the direct URL, I wanted the ul already came with the Collapse in in its class ( Already come open )
– Jackson
It is not enough to pass a parameter via
props
and use a:class="{'CLASS_COLLAPSE': isProps}"
?– Rafael Augusto
I don’t quite understand how I would use Props to my advantage in this case... I made an image if I can better understand how classes work: https://i.imgur.com/P0m8s1m.jpg
– Jackson
You’re using routes, right?
– Rafael Augusto
Let’s go continue this discussion in chat.
– Jackson