国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

Vue.js基礎學習之class與樣式綁定

2019-11-19 17:06:26
字體:
來源:轉載
供稿:網友

打著鞏固 css 知識的旗號開始了對 vue 樣式綁定的研究,相比前一篇的 demo,本次內容多了各種樣式在里面,變得稍微花哨了些,話不多說,直接上代碼吧:

<html><head> <meta charset="utf-8"> <title>Vue test</title> <style type="text/css"> body {font-family: Verdana;} p { font-family: Times, "Times New Roman", serif;} .static.active {color: green; font-size: 35px;} div.text-danger {color: red;font-size: 25px;} div.active {color: blue;font-family: Verdana;} </style> <script src="./vue.min.js"></script></head><body><div id="app"> <!-- Create an instance of the todo-item component --> <todo-item></todo-item></div><div class="static" v-bind:class="{ active: isActive, 'text-danger': hasError }"> <p>class property set.</p></div><div id="app3"  v-bind:class="[activeClass,errorClass]"> <p>group class property set.</p></div><div id="app4" v-bind:class="[isActive ? 'active' : 'text-danger']"> <p>三元表達式加樣式</p></div><div id="app5"> <my-component v-bind:class="{ active: isActive }"></my-component> </div><div id="app6"> <p v-bind:style="{ color: activeColor, fontSize: fontSize + 'px' }">綁定內聯樣式</p> <p v-bind:style="styleObject">對象樣式綁定</p></div><script>Vue.component('todo-item', { template: '<p>todo test.</p>'})// 一定要實例化才能用var app = new Vue({ el: '#app'})// 用類選擇器構造一個Vue對象并綁定額外的class屬性var app2 = new Vue({ el: '.static', data: { isActive: false, hasError: true }})// 數組語法加 class (因為是從下往上拿樣式,所以text-danger的color樣式被覆蓋)var app3 = new Vue({ el: '#app3', data: { activeClass: 'active', errorClass: 'text-danger' }})var app4 = new Vue({ el: '#app4', data: { isActive: true }})Vue.component('my-component',{ template: '<p class="static">在已經定義好樣式的自定義組件上加樣式</p>'})var app5 = new Vue({ el: '#app5', data: { isActive: true }})// 綁定內聯樣式var app6 = new Vue({ el: '#app6', data: { activeColor: '#FF00FF', fontSize: 30, styleObject: {  color: '#585858',  fontSize: '25px' } }})</script></body></html>

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 天峨县| 乐亭县| 海林市| 兴国县| 衡阳县| 九龙县| 教育| 长治市| 高雄市| 宝鸡市| 景洪市| 漳浦县| 梁平县| 喀喇沁旗| 合江县| 会理县| 汨罗市| 柘城县| 湖北省| 永春县| 七台河市| 静安区| 南昌县| 和平区| 石阡县| 张家口市| 报价| 吉水县| 惠水县| 武威市| 磐石市| 兴业县| 永靖县| 洛浦县| 孙吴县| 湘潭县| 藁城市| 宾阳县| 固阳县| 天等县| 河间市|