vuejs点击class变化的实例
时间:2021-05-13 08:11:32|栏目:vue|点击: 次
如下所示:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Vue.js小demo</title> <style> .static{ width: 100px; height: 60px; margin:30px auto; display: inline-block; cursor: pointer; } .class-a{ background: lightpink; } .class-b{ background: #eee; } </style> </head> <body> <div id="content"> <span class="static" v-bind:class="{'class-a':isA,'class-b':!isA}" @click="toggle"></span> </div> </body> <script src="https://cdn.bootcss.com/vue/2.2.6/vue.js"></script> <script> var vm=new Vue({ el:"#content", data:function(){ return { isA:false }; }, methods:{ toggle:function(){ this.isA=!this.isA; } } }); </script> </html>