注意:
- 凡是有-的style屬性名都要變成駝峰式觉义,比如font-size要變成fontSize
- 除了綁定值设拟,其他的屬性名的值要用引號括起來衷咽,比如backgroundColor:'#00a2ff'而不是 backgroundColor:#00a2ff
【對象】
html :style="{ color: activeColor, fontSize: fontSize + 'px' }"
html :style="{ color: ( index ==0 ? conFontColor : '#000' ) }"
總結:對象寫法多個樣式用逗號隔開,表達式用括號括起來蒜绽,屬性值用引號
【數(shù)組】
html :style="[baseStyles, overridingStyles]"
html :style="[ {color:(index==0?conFontColor:'#000') }, {fontSize: '20px'} ]"
【三目運算符】
html :style="{ color: (index==0 ? conFontColor : '#000' ) }"
html :style="[ {color: (index ==0 ? conFontColor : '#000') }, {fontSize:'20px'} ]"
【多重值】
*html :style="{ display: ['-webkit-box', '-ms-flexbox', 'flex'] }"
此時镶骗,瀏覽器會根據(jù)運行支持情況進行選擇
【綁定data對象】
- html :style="styleObject"
data() {
return{
styleObject: {
color: 'red',
fontSize: '13px'
}
}
}
綁定Class
- 類名active依賴于數(shù)據(jù)isActive,當其為true時候,div會擁有類名active,為false時則沒
:class="{'active':ifActive}"
- 綁定多個動態(tài)的
:class="{'active':isActive, 'error':isError}"
- 動態(tài)class和靜態(tài)的結合
:class="[ dataMap == 'worldmap' ? 'active_map' : '' ]"
:class="['home_map',dataMap == 'worldmap' ? 'active_map' : '' ,'normal_bg' ]"
// 前后都可以加靜態(tài)css
- 三目運算符
:class="flag ? 'pective' : 'pectiveD'"
:class="stepData['phase'] >=1? 'finish': 'unfinish'"
- 數(shù)組方法
:class="[atvieCls,errorCls]"
data:{
atvieCls:'active',
errorCls:'error'
}