vue動態新增style樣式
阿新 • • 發佈:2021-10-11
注意:
凡是有-的style屬性名都要變成駝峰式,比如font-size要變成fontSize
除了繫結值,其他的屬性名的值要用引號括起來,比如backgroundColor:'#00a2ff'而不是 backgroundColor:#00a2ff
【物件】
html :style="{ color: activeColor, fontSize: fontSize + 'px' }"
html :style="{color:(index==0?conFontColor:'#000')}"
【陣列】
html :style="[baseStyles, overridingStyles]"
html :style="[{color:(index0?conFontColor:'#000')},{fontSize:'20px'}]"
【三目運算子】
html :style="{color:(index
html :style="[{color:(index==0?conFontColor:'#000')},{fontSize:'20px'}]"
【多重值】
此時,瀏覽器會根據執行支援情況進行選擇
html :style="{ display: ['-webkit-box', '-ms-flexbox', 'flex'] }"
【繫結data物件】
html :style="styleObject"
data() { return{ styleObject: { color: 'red', fontSize: '13px' } } }