Bind multiple classes to a single variable

让人想犯罪 __ 提交于 2020-08-20 11:15:30

问题


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 }?


回答1:


You can combine both classes into the same property:

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


来源:https://stackoverflow.com/questions/60471976/bind-multiple-classes-to-a-single-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!