Answer the question
In order to leave comments, you need to log in
How to add a class to the clicked element?
<div class="block-calculations__panel" v-for=" (i, index) in arr ">
<span :data-col="index" @click="isActive = !isActive" v-bind:class="{ active: isActive }"></span>
</div>
Answer the question
In order to leave comments, you need to log in
Instead of a generic isActive , add this property to each element in arr , and change it:
<div v-for="(n, i) in arr" class="block-calculations__panel">
<span
:data-col="i"
:class="{ active: n.isActive }"
@click="n.isActive = !n.isActive"
></span>
</div>
<div v-for="(n, i) in arr" class="block-calculations__panel">
<span
:data-col="i"
:class="{ active: active === i }"
@click="active = active === i ? null : i"
></span>
</div>
<span @click="method">
...
methods: {
method(e){
e.target.classList.add('isActive');
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question