- <!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>
vuejs点击class变化
最新推荐文章于 2024-07-16 20:15:00 发布