VueJS Add active class li onClick navigation menu item

VueJS Add active class li onClick navigation menu item

Today, We want to share with you VueJS Add active class li onClick navigation menu item.In this post we will show you add/remove active class for ul list with vue js, hear for Add Active Navigation Class Based on URL using VueJS we will give you demo and example for implement.In this post, we will learn about Add active class to navigation menu item based on URL using VueJS with an example.

VueJS Add active class li onClick navigation menu item

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.

  PHP Laravel 5.7 Get IP Address Example

<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;
}

VueJS Active Item
Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about VueJS Add active class li onClick navigation menu item.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

  Session Management in CodeIgniter with PHP

Leave a Reply

avatar
  Subscribe  
Notify of