Vue中通過屬性綁定為元素綁定style行內樣式的實例代碼
1.直接在元素上通過:style的形式,書寫樣式對象
<h1 :style='{color:’red’,’font-weight’:200}'>這是一個H1</h1>
2.將樣式對象定義在data中,并直接引用到:style中
1:在data上定義樣式
data:{ styleObj1:{color:’blue’,’font-weight’:200,’font-size’:’40px’},}
2:在元素中,通過屬性綁定的形式,將樣式對象應用到元素中
<h1 :style='styleObj1'>這是一個H1</h1>
3.在:style中通過數組,引用多個data上的樣式對象
1:在data上定義樣式
data:{ styleObj1:{color:’blue’,’font-weight’:200,’font-size’:’40px’}, styleObj2:{’font-style’:’italic’},}
2:在元素中,通過屬性綁定的形式,將樣式對象應用到元素中
<h1 :style='[styleObj1,styleObj2]'>這是一個H1</h1>
完整代碼:
<html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8' /></head><body> <div id=’app’> <h1 :style='{color:’red’,’font-weight’:200}'>這是一個H1</h1> <h1 :style='styleObj1'>這是一個H1</h1> <h1 :style='[styleObj1,styleObj2]'>這是一個H1</h1> </div></body><script src='http://www.leifengta.com.cn/bcjs/vue.min.js'></script><script> var vm = new Vue({ el:’#app’, data:{ styleObj1:{color:’blue’,’font-weight’:200,’font-size’:’40px’}, styleObj2:{’font-style’:’italic’}, } });</script></html>
到此這篇關于Vue中通過屬性綁定為元素綁定style行內樣式的文章就介紹到這了,更多相關vue style行內樣式內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!
相關文章:
1. Android如何加載Base64編碼格式圖片2. 詳解Android studio 動態fragment的用法3. 解決Android studio xml界面無法預覽問題4. 基于android studio的layout的xml文件的創建方式5. 圖文詳解vue中proto文件的函數調用6. Spring Boot和Thymeleaf整合結合JPA實現分頁效果(實例代碼)7. 什么是python的自省8. 使用Android studio查看Kotlin的字節碼教程9. Vuex localStorage的具體使用10. Vue封裝一個TodoList的案例與瀏覽器本地緩存的應用實現

網公網安備