Answer the question
In order to leave comments, you need to log in
How to add/remove a class on click on an element (Vue)?
Hello, not in the dock, not on the Internet, I can’t find how to add / remove a class specifically for this element in Vue by clicking on an element? I have 5 elements, for example, I want that by clicking on one, the 'active' class is added to it and removed by a second click.
I'm trying to do it through :class and a normal method that changes true/false (like in the dock), but I'm getting added/removed on all elements at once. There must be some simple analogue of $(this).add/removeClass('active').
Answer the question
In order to leave comments, you need to log in
There must be some simple analogue of $(this).add/removeClass('active').
this.el.classList.add('active')
this.el.classList.remove('active')
<div class = "name active" ref = "needed" @click = "$refs.needed.classList.toggle('active')">
</div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question