Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bind multiple classes to a single variable

While using Tailwind with utility-first approach to css, I often find the need to bind multiple classes to a single variable.

For instance, to style an input form, I need to add border-red, color-red, etc if there is an error.

Is there a nice and elegant way to express this in Vue instead of writing v-bind:class="{ 'border-red': error, 'text-red': error }?

like image 690
emk Avatar asked Jan 24 '26 12:01

emk


1 Answers

You can combine both classes into the same property:

:class="{ 'border-red text-red': error }"
like image 59
Decade Moon Avatar answered Jan 27 '26 04:01

Decade Moon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!