将多个 类 绑定到单个变量

Bind multiple classes to a single variable

在使用 Tailwind 和实用程序优先方法 css 时,我经常发现需要将多个 类 绑定到单个变量。

例如,要设置输入表单的样式,如果出现错误,我需要添加 border-redcolor-red 等。

在 Vue 中有没有一种很好的优雅的方式来表达这个而不是写 v-bind:class="{ 'border-red': error, 'text-red': error }

您可以将两个 类 组合成同一个 属性:

:class="{ 'border-red text-red': error }"