动态绑定样式
<ol class="rate"> <li class="rateListDom" ref="rateListDom" v-for="(item, ind) in rateArr" :key="ind" :class="{rateChecked: ind === checkedRate}" @click="rateToggle(ind)" :style="styleObject"> <em>{{item.num}}</em><p>{{item.txt}}</p> </li> </ol>
data中
styleObject: { width: '2.6rem', marginRight: '0.8rem' }
示例2:
当样式逻辑复杂时,抽取出来写到计算属性
<div :style="activeStyle"><slot name="item-text"></slot></div>
activeStyle(){ return this.isActive?{color:this.activeColor}:{} }