欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue通過style或者class改變樣式的實例代碼

 更新時間:2018年10月30日 11:46:43   作者:taylorkk  
這篇文章主要介紹了vue通過style或者class改變樣式的實例代碼,在文中給大家提到了vue的一些樣式(class/style)綁定,需要的朋友可以參考下

通過style改變樣式

<div :style="{ 'min-height': size + 'px' }"></div> 
<div :style="[{ 'min-height': size + 'px' },{color:'red'}]"></div> 
<div :style="{ 'opacity': value ? 0.5 : 1 }"></div> 

通過className改變樣式

​<div class="static"
   v-bind:class="{ active: isActive, 'text-danger': hasError }">
</div>

<script>
data: {
 isActive: true,
 hasError: false
}
</script>

<style>
.active{
  ...
}
.text-danger{
  ...
}
</style>

PS:下面看下Vue的一些樣式(class/style)綁定

樣式有兩種:class、style

class

  1、對象語法

   ?、賯鹘o :class 一個對象

    比如:

<div :class="{ active : isActive}"></div>

    在這里,isActive的真值決定active這個樣式是否顯示

    ②傳給 :class 一個對象變量

    再比如,可以直接綁定一個對象

<div :class = "duixiang" ></div>

export default{
  data(){
   return{
    duixiang :{
     active : true
    }
   }
  } 
}

    ③在②的基礎(chǔ)上,把這個對象變量放到computed計算屬性里

data: {
 isActive: true,
 error: null
},
computed: {
 classObject: function () {
  return {
   active: this.isActive && !this.error,
   'text-danger': this.error && this.error.type === 'fatal',
  }
 }
}

  2、數(shù)組語法

    傳給 :class 一個數(shù)組(數(shù)組里面是變量名,然后具體變量名所指的內(nèi)容寫到data里)

<div :class = "[ n , i]"> </div>
export default{
 data(){
  return{
   n : ' active ',
   i : ' text-danger ',
  }
  }
}

     上面的代碼在最后會宣傳成為<div class = "active text-anger"></div>

style

  1、對象語法

   ?、賯鹘o :style一個對象(這個對象是個JavaScript對象)。記??!CSS屬性名可以用駝峰式命名

<div :style = " { color : activeColor , fontSize : fontSize + 'px' } "></div>
//然后在data里面寫明,冒號后邊的這個變量的實際內(nèi)容,如果是單位,像px這種就直接用字符串引著就行了
data: {
 activeColor: 'red',
 fontSize: 30
}  

   ?、趥鹘o :style一個對象變量。

<div v-bind:style="styleObject"></div>
//然后在data聲明這個對象變量是指代一個怎樣具體的對象
data: {
 styleObject: {
  color: 'red',
  fontSize: '13px'
 }
}

同樣的,對象語法常常結(jié)合返回對象的計算屬性使用。

總結(jié)

以上所述是小編給大家介紹的vue通過style或者class改變樣式的實例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評論