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.

Read Also:  AngularJS Login Script using PHP MySQL

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.

Read Also:  Triggering callback after user stops typing jQuery

<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 :

Read Also:  Laravel 6 Eloquent Joins Queries Example Tutorial

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.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Date Filter Using Angular Example with Demo
  2. Read Also:  How to create an visitor counter with HTML & PHP?
  3. Read Also:  PHP Ajax Autocomplete Search from Database Example
  4. Read Also:  Dropzone Multiple Image upload validation
  5. Read Also:  jQuery Removing All Spaces From String
  6. Read Also:  PHP Object Cloning Magic Methods Example
  7. Read Also:  Upload video files Images using PHP mysql
  8. Read Also:  PHP Object Cloning Magic Methods Example
  9. Read Also:  Upload video files Images using PHP mysql
  10. Read Also:  AngularJS Login Script using PHP MySQL
CLOSEX