code:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Vue中CSS动画原理</title>
<script type="text/javascript" src="js/vue.js" ></script>
<style>
.fade-enter,.fade-leave-to{
opacity: 0;
}
.fade-enter-active,.fade-leave-active{
transition: opacity 3s;
}
</style>
</head>
<body>
<div id="root">
<!--name以fade命名,样式那以fade开头,不用name,则样式以v开头-->
<!--要想用哪个地方有动画效果就把transition标签加上去-->
<transition name="fade">
<div v-if="show">hello world</div>
</transition>
<button @click="handleClick">切换</button>
</div>
<script>
new Vue({
el:"#root",
data:{
show:true
},
methods:{
handleClick(){
this.show=!this.show
}
}
})
</script>
</body>
</html>