Fork me on github

动态绑定样式

    <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}:{}
 }

 

posted @ 2021-03-17 17:39  我の前端日记  阅读(49)  评论(0编辑  收藏  举报
Copyright © 2021 LinCangHai
Powered by .NET 5.0 on Kubernetes