Answer the question
In order to leave comments, you need to log in
How to open dynamically created elements?
There is a code
<ul>
<li v-for="(Item, Index) in Navigation" :key="Index">
<div>
<Nuxt-link :to="Item.Link">{{Item.Name}}</Nuxt-link>
<span @click="SubNavActive = !SubNavActive"></span>
</div>
<ul :class="{active: SubNavActive}">
<li v-for="(Item, Index) in Item.SubNav" :key="Index">
<Nuxt-link :to="Item.Link">{{Item.Name}}</Nuxt-link>
</li>
</ul>
</li>
</ul>
<script>
export default {
data () {
return {
SubNavActive: false,
}
}
}
</script>
Answer the question
In order to leave comments, you need to log in
index for loops is better not to use, add a field with a unique id to the object and use it instead of index. And it's also worth everything that is possible to take out of the template
Save the id of the item this.activeItem = index
The code for the active class will look like this :class="{ active: activeItem === index }"
PS.
Can CSS hover or focus be used?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question