1. 程式人生 > 實用技巧 >vue過場動畫

vue過場動畫

<template>
  <div id="app">
    <transition :enter-active-class="enterTransition" :leave-active-class="leaveTransition">
      <keep-alive>
        <router-view class="routeView" />
      </keep-alive>
    </transition>
  </div>
</template>

<script
> import myhea from "@/components/hea.vue"; import myfooter from "@/components/footer.vue"; export default { name: "App", components: { myhea, myfooter, }, data() { return { enterTransition: "animate__animated animate__fadeIn", leaveTransition: "animate__animated animate__fadeOut", }; }, watch: { $route(to, from) { let toDepth = to.meta.depth; let fromDepth = from.meta.depth; if (fromDepth > toDepth) { this.enterTransition = "animate__animated animate__fadeInLeft"; this.leaveTransition = "animate__animated animate__fadeOutRight"; } else if (fromDepth
< toDepth) { this.enterTransition = "animate__animated animate__fadeInRight"; this.leaveTransition = "animate__animated animate__fadeOutLeft"; } else { this.enterTransition = "animate__animated animate__fadeIn"; this.leaveTransition = "animate__animated animate__fadeOut"
; } }, }, }; </script> <style> .routeView { position: absolute; left: 0; right: 0; top: 0; bottom: 0; } * { margin: 0px; padding: 0px; } #app { min-width: 20rem; font-family: Avenir, Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-align: center; color: #2c3e50; } </style>
$ npm install animate.css --save