多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
~~~ <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Vue中的样式绑定</title> <script src="vue.js"></script> <style> .activated { color: red; } .activited_one { font-size: 30px; } </style> </head> <body> <div id="app"> <!-- class对象绑定--> <!-- class数组绑定--> <!-- <div @click="handleDivClick" :class="{activated:isActivated}">--> <!-- <div @click="handleDivClick" :class="[activited,activitedOne]">--> <!-- <div @click="handleDivClick" :style="styleObj">--> <div @click="handleDivClick" :style="[styleObj,{fontSize:'20px'}]"> Hello World </div> </div> <script> var vm = new Vue({ el: '#app', data: { isActivated: false, activited: '', activitedOne: 'activited_one', styleObj: { color: "black" } }, methods: { handleDivClick: function () { // this.isActivated = !this.isActivated // this.activited = this.activited == 'activated' ? '' : 'activated'; this.styleObj.color = this.styleObj.color == 'black' ? 'red' : 'black'; } } }); </script> </body> </html> ~~~