刚开始使用Vue,所以我不能让这个简单的东西工作.我想做的就是根据条件切换一个类.
<button type="button"
class="btn dropdown-toggle"
v-bind:class="{ btn-default: (search.category != 'all') }">
{{ filterCategoryText || 'Category' }}
</button>
刚开始使用Vue,所以我不能让这个简单的东西工作.我想做的就是根据条件切换一个类.
<button type="button"
class="btn dropdown-toggle"
v-bind:class="{ btn-default: (search.category != 'all') }">
{{ filterCategoryText || 'Category' }}
</button>
首先,正如您所发现的,您可能应该删除重复的类定义.可以在绑定类定义中混合使用静态类和动态类.(如果你把副本留在那里,它仍然有效)
然后,你可以 Select ...
Object syntax
// property names will be in the class list if their values are truthy
:class="{
'btn-default': search.category != "all",
'btn' : true,
'dropdown-toggle' : true
}"
Array syntax
// an item in the array becomes a class in the class list
:class="[
search.category != 'all' ? 'btn-default':'',
'btn',
'dropdown-toggle'
]"
Simple expression
// if you only have one item, just use a simple expression
:class="search.category != 'all' ? 'btn-default':''"
100