vue动态添加style样式


注意:

凡是有-的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
0?conFontColor:'#000')}"
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'
      }  
    }
}

转载于:https://juejin.im/post/5d5dfbde6fb9a06b122f4226


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM