<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .active { width: 100px; height: 100px; border: 1px solid red; } .error { background-color: orange; } .test { color: green; } .base { font-size: 28px; } </style> </head> <body> <div id="app"> <div v-bind:class="[activeClass,errorClass,{test:isTest}]"> 我是歌谣 </div> <div v-bind:class='arrClasses'></div> <div v-bind:class='objClasses'></div> <button v-on:click="handle">切换</button> <div class="base" v-bind:class='objClasses'></div> </div> <script type="text/javascript" src="./js/vue.js"></script> <script> /* //对象绑定的值可以和数组结合使用 //class绑定的值可以简化操作 //默认的class如何处理 默认的class会保留 */ var vm = new Vue({ //绑定的标签 el: '#app', //自定义按键修饰符 data: { activeClass: 'active', errorClass: 'error', isTest: true, arrClasses: ['active', 'error'], objClasses: { active: true, error: true } }, methods: { handle: function() { //控制isactive奇幻 this.activeClass = ''; this.errorClass = ''; isTest = true; this.objClasses.error = false; } } }); </script> </body> </html>