<!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>

Logo

前往低代码交流专区

更多推荐