Add Active Class to Navigation Menu Item on Click in VueJS

There are the Following The simple About VueJS Add active class li onClick navigation menu item Full Information With Example and source code.

As I will cover this Post with live Working example to develop VueJS Add active class to main menu, so the some major files and Directory structures for this example is following below.

  • index.html
  • main.js
  • style.css

HTML Interface

index.html

This is where I will make a simple HTML form and PHP server side source code for our web application. To make the forms simply all souce code copy and write it into your any text editor Like Notepad++, then save file it as index.html.

<h2>VueJS Add active class to main menu</h2>
<div id="myApp">
<span>{{activeId}}</span>

<ul >
<li v-for="mem in members">
<button v-bind:class="{ active: (mem.id === activeId) }" v-on:click="selectMember(mem.id)">
{{ mem.status }}
</button>
</li>
</ul>
</div>

Vuejs Files

vuejs main logic script

new Vue({
el: '#myApp',
data: {
activeId : 0,
members: [
{ id :1, status: 'Jaydeep 1' },
{ id :2, status: 'Rakesh 2' },
{ id :3, status: 'Krunal 3' },
]
},
methods: {
selectMember: function (id) {
this.activeId = id;
}
}
})

style.css

Custom css style

.active {
color : green;
}

I hope you get an idea about VueJS Add active class li onClick navigation menu item.


#vue #vuejs 

Add Active Class to Navigation Menu Item on Click in VueJS
1.40 GEEK