vuejs点击class变化
Vue.js小demo.static{width: 100px;height: 60px;margin:30px auto;display: inline-block;cursor: pointer;}.class-a{background: lightpink;}.class-b{background: #eee;}
·
<!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>
更多推荐
已为社区贡献8条内容
所有评论(0)