<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="vue.js"></script> <style> .class1{ color: red; } .class2{ font-size:120px; } </style> </head> <body> <div id="app"> <div :class="{class1:isFalse,class2:isFalse}" @click="handleClick">我是class对象的方式</div> <div :class="[class3,class4]" @click="handleClick1">我是class数组的方式</div> <div class="class1">非动态绑定</div> <div :style="style1" @click="handleClick2">我是style对象的方式</div> <div :style="[style1,{backgroundColor:'black'}]" @click="handleClick2">我是class数组的方式</div> <div style="color: red">非动态绑定</div> </div> <script> var app=new Vue({ el:"#app", data:{ isFalse:false, class3:null, class4:null, style1:{ color:'black', fontSize:'10px' } }, methods:{ handleClick:function () { this.isFalse=!this.isFalse }, handleClick1:function () { this.class3=this.class3==null?"class1":null; this.class4=this.class4==null?"class2":null; }, handleClick2:function () { this.style1.color=this.style1.color=='red'?"black":'red'; this.style1.fontSize=this.style1.fontSize=='120px'?"12px":'120px'; } } }) </script> </body> </html>