What you are referring to is the concept of dynamic class bindings.
v-if
is used for conditional rendering, determining whether an element should be displayed on the screen or not.
By utilizing class bindings, you can assign a class, such as "style1" or "style2", to an element based on certain conditions:
<p v-for="car in cars" :key="car.id"
:class="{
style1: car.color === 'red',
style2: car.color === 'blue'
}">
{{ car.name}}
</p>
You can also use a function like
:class="someFunction(car.color)"
(as mentioned by Jaromanda X in a comment).
Vue Playground example
Although using v-if with v-for may not directly relate to your current issue, it's good to know that you can use both simultaneously, just not on the same element. The Vue documentation provides a solution:
Avoid using v-if and v-for together on the same element to prevent implicit precedence issues
To address this, move v-for to a parent tag for clearer visibility
<template v-for="todo in todos">
<li v-if="!todo.isComplete">
{{ todo.name }}
</li>
</template>