从隐藏到显现
从显现到隐藏
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Vue中的动画</title>
<style>
.fade-enter,
.fade-leave-to {
opacity: 0;
}
.fade-enter-active,
.fade-leave-active {
transition: opacity 3s;
} </style>
</head>
<body>
<div id="app">
<transition name="fade">
<div v-if="show">hello world</div>
</transition>
<button @click="handleBtnClick">change</button>
</div> <!-- 开发环境版本,包含了用帮助的命令行警告 -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script type="text/javascript"> var app = new Vue({
el: '#app',
data: {
show: true
},
methods: {
handleBtnClick: function() {
this.show = !this.show;
}
}
}) </script>
</body>
</html>
动画由transition标签包裹,class中的名字由transition的name属性来定,例如name = "fade",则class名为.fade-enter,如果没有name,则默认class名为v-, 例如.v-enter, .v-enter-active