Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bind multiple classes with one condition in Vue [duplicate]

For example, I had expected something like this to work in that way with using a single condition and setting an array of classes at once:

<div v-bind:class="{['bg-red-500','bg-white']:isActive}">
...
</div>

How can I bind multiple classes with a single condition in Vue without using an extra function?

like image 204
Marian Klühspies Avatar asked Dec 11 '22 00:12

Marian Klühspies


1 Answers

This should work:

<div :class="[isActive ? ['bg-red-500','bg-white'] : '']">
 ...
</div>
like image 82
Zhivko Zhelev Avatar answered Feb 12 '23 08:02

Zhivko Zhelev