动态class的几种写法

1.

<button @click="setState(0)" :class="{active:state===0}">按钮</button>
button {
  display: block;
  width: 165px;
  height: 46px;
  font-size: $font-big;
  /*background: linear-gradient(#1f3052, #1e283b);*/
  background: #4A8074;
  box-sizing: border-box;
  border: 2px solid transparent;
  cursor: pointer;
  color: $font-color-normal;
  font-weight: bold;
  margin-bottom: 10px;
  outline: none;

  &.active {
    background: linear-gradient(#3a97a8, #0b5d74);
    border: 2px solid #2e4e5d;
  }
}
2.
<div class="control" :class="{play: !play, pause: play}" @click="clickControl"></div>

play:true

.control {
  width: 64px;
  height: 64px;
  cursor: pointer;

  &.play {
    background-image: url("../../../static/images/mutiplyHistory/play.png");
  }
  &.pause {
    background-image: url("../../../static/images/mutiplyHistory/pause.png");
  }
}

3.

<div :class="['picDiv',item.selected?'divSelected':'']" @click="setStyleToPic">
.picDiv{
  width: 64px;
  height:64px;
  float: left;
  img{
    width: 64px;
    height: 64px;
  }
  &.divSelected{
    width: 72px;
    height:72px;
    img{
      width: 72px;
      height: 72px;
    }
  }
}

4.

<div :class="[rightBtnIsSelected?'yes':'no','nextImg']"></div>
.nextImg{
  cursor: pointer;
  position: absolute;
  bottom: $turn-logo-bottom;
  right: $turn-logo-right;
  pointer-events: auto;
  &.yes{
    
  }
  &.no{
   
  }

}
  • 3
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值