绑定class -vue

1、值为对象

:class = "{ 'text-red': isActive }"
data () {
  return {
    isActive : true
  }
}

 

:class = "color"
data () {
 return {
    color: {
      'text-red': true
    }
 }
}

 

:class = "color"
computed: {
   color: function () {
      return {
         'text-red' : true
      }
  }
}

2、值为数组

:class = "[color1, color2]"
data (){
  return {
     color1: "text-red",
     color2: "text-green"
  }
}

 

:class="[isActive ? activeCls : '',errorCls]"
data (){
  return {
     isActive:true,
     atvieCls:'active',
     errorCls:'error'
  }
}

 

:class="[{'active':isActive},errorCls]"
 data () {
   return {
      isActive:true,
      errorCls:'error'
   }    
}
posted @ 2019-12-04 21:16  雨夜稻草  阅读(141)  评论(0编辑  收藏  举报