How to dynamically add activity class for menu loop in Vue Js?
P粉793532469
2023-08-25 20:24:48
<p>How to add an active class in a loop that dynamically displays menus? I can't set activity class for opened menu. </p>
<pre class="brush:php;toolbar:false;"><a v-bind:href="module.route" class="nav-link">
//module.route is a database column
<i :class="module.icon" ></i>
//module.icon is a database column
<p>
{{ module.name }}
//module.name is a database column
</p>
</a></pre>
</li>
<p>It displays the menu list from the database. Now I just want to make the open menu active. </p>
I did this.
I added all the tabs I wanted in an array called
tabs
.This will create a
<li>
element for eachtab
in the arraytabs
.All elements will have the
nav-link
class, and usev-bind
, if the variableactive_tab
is equal totab
, will addactive
to the element's class list. Whenever the user clicks one of the tabs, use@click
to change theactive_tab
to thetab
that the user clicked.style