<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> .activeColor{ color: red; } </style> <body> <!--mvvm里面的v--> <div id="app"> <div :class="setClass"> 你好 </div> </div> <script src="./node_modules/vue/dist/vue.js"></script> <script > //这是mvvm里面的vm var vm=new Vue({ el:'#app', //这是mvvm里面的m data:{ isActive:true, error:true }, computed:{ setClass:function(){ return{ activeColor:this.isActive && this.error } } } }) </script> </body> </html>