Vue動畫--元件的過渡
阿新 • • 發佈:2018-11-08
code:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Vue中元件的過渡</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 1s; } </style> </head> <body> <div id="root"> <transition name="fade" mode="out-in"> <component :is="type"></component> </transition> <button @click="handleClick">切換</button> </div> <script> Vue.component('child',{ template:'<div>child</div>' }) Vue.component('child-one',{ template:'<div>child-one</div>' }) new Vue({ el:"#root", data:{ type:"child" }, methods:{ handleClick(){ this.type=this.type==='child'?'child-one':'child' } } }) </script> </body> </html>