Vue中CSS动画原理
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Vue中CSS动画原理</title> <script src="./vue.js"></script> <style> .v-enter, .v-leave-to{ opacity:0; } .v-enter-active, .v-leave-active { transition:opacity 3s; } </style> </head> <body> <div id="root"> <transition> <!--加动画效果--> <div v-if="show">hello world</div> <!--v-if与v-show都是可以带动画效果的--> </transition> <button @click="handleClick">切换</button> </div> <script> var vm = new Vue({ el:'#root', data:{ show:true }, methods:{ handleClick:function () { this.show = !this.show } } }) </script> </body> </html>