使用场景:
- 带单当前选中项cur样式判定;
- 不同模块参数不同颜色显示;
使用方法:
- 对象语法
- <div class="static" v-bind:class="{ active: isActive, 'text-danger': hasError }"></div>
data如下:
data: { isActive: true, hasError: false }
渲染结果:
<div class="static active"></div>
- <div class="static" v-bind:class="{ active: isActive, 'text-danger': hasError }"></div>
- 数组语法
- <div v-bind:class="[activeClass, errorClass]"></div>
- <div v-bind:class="[isActive ? activeClass : '', errorClass]"></div>
- <div v-bind:class="[{ active: isActive }, errorClass]"></div>