Answer the question
In order to leave comments, you need to log in
How to access an element attribute to conditionally set a class?
Let's say we have a list of elements.
<li class="tile red" data-tile="1"></li>
<li class="tile blue" data-tile="2"></li>
<li class="tile yellow" data-tile="3"></li>
<li class="tile green" data-tile="4"></li>
props: {
currentSector: Number
}
:class="[this.currentSector === (здесь значение атрибута) ? 'hightlighted' : '' ]"
Answer the question
In order to leave comments, you need to log in
If you have this list built through v-for, then it doesn’t cost anything to slip the right class on the right element.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question