【问题标题】:Bind multiple classes to a single variable将多个类绑定到单个变量
【发布时间】:2020-06-13 18:04:45
【问题描述】:

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

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

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

【问题讨论】:

    标签: vue.js tailwind-css


    【解决方案1】:

    您可以将两个类合并到同一个属性中:

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

    【讨论】:

      猜你喜欢
      • 2013-07-14
      • 2019-09-16
      • 1970-01-01
      • 2018-11-21
      • 2011-05-10
      • 2014-10-31
      • 1970-01-01
      • 1970-01-01
      • 2011-02-07
      相关资源
      最近更新 更多