vue移动端添加路由动画

这一生的挚爱 提交于 2020-03-10 11:59:37
<template>
  <div id="app" >
    <transition :name="transitionName" >
      <router-view class="appView"></router-view>
    </transition>
  </div>
</template>

<script>
export default {
  name: 'App',
  data () {
    return {
      transitionName: ''
    }
  },
  watch: {
    '$route' (to, from) {
      const toRouterLevel = to.meta.routerLevel
      const fromRouterLevel = from.meta.routerLevel
      console.log(fromRouterLevel)
      console.log(toRouterLevel)
      // console.log(to, from)
      // const toDepth = to.path.split('/').length
      // const fromDepth = from.path.split('/').length
      // console.log(to.path)
      // console.log(from.path)
      if (toRouterLevel > fromRouterLevel) {
        console.log('slide-left')
        this.transitionName ='slide-left' 
      } else if(toRouterLevel < fromRouterLevel) {
        console.log('slide-right')
        this.transitionName ='slide-right'
      }
    }
  }
}
</script>
<style>
 .slide-right-enter-active,
  .slide-right-leave-active,
  .slide-left-enter-active,
  .slide-left-leave-active {
    will-change: transform;
    transition: all .5s;
    position: absolute;
    height: 100vh;
  }
  .slide-right-enter {
    opacity: 0;
    transform: translate3d(-100%, 0, 0);
  }
  .slide-right-leave-active {
    opacity: 0;
    transform: translate3d(100%, 0, 0);
  }
  .slide-left-enter {
    opacity: 0;
    transform: translate3d(100%, 0, 0);
  }
  .slide-left-leave-active {
    opacity: 0;
    transform: translate3d(-100%, 0, 0);
  }
</style>

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!