1.代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#box{
width: 300px;
height: 300px;
border:1px solid blue;
margin: 10px;
}
.blue{
background-color:red;
box-shadow: 5px 5px 5px red;
}
</style>
</head>
<body>
<div id="app">
<button @click="seen=true">显示</button>
<button @click="hide()">隐藏</button>
<button v-on:click="seen=!seen"> 切换</button>
<button @click="isBlue=true">增加类</button>
<button @click="delClass()">删除类</button>
<button v-on:click="isBlue=!isBlue">切换类</button>
<div id="box" :class="{blue:isBlue}" v-if="seen"></div>//isBlue为真这个bule类起作用
</div>
<script src="./vue.js"></script>
<script>
var vm=new Vue({
el:"#app",
data:{
seen:true,
isBlue:true
},
methods:{
hide(){
this.seen=false;
},
delClass:function(){
this.isBlue=false;
}
}
});
</script>
</body>
</html>
2.预览效果1.png