S
S
Sector5672020-05-01 16:46:25
Vue.js
Sector567, 2020-05-01 16:46:25

How to highlight active menu item in vue.js?

There is a menu

<ul>
                <li
                    v-for="(item, index) in menuList"
                    :key="index">
                    <a>{{item}}</a>
                </li>
            </ul>


How can I change the color of the active menu item?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
origami1024, 2020-05-01
@Sector567

<a :class="{active: item == currentlyActiveItem}">{{item}}</a>

active - this is the name of the
item class - this is what you already use in the cycle
currentlyActiveItem - a variable from data that stores the current active item
https://ru.vuejs.org/v2/guide/class-and-style.html - read here
https://codepen.io/Bondar/pen/OzWYNd - here's another example

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question