class與computed一起應用
阿新 • • 發佈:2018-05-22
col body viewport title pat ted view pre ive
<!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>
class與computed一起應用