vue 页面过渡效果

Posted xielisen

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vue 页面过渡效果相关的知识,希望对你有一定的参考价值。

App.vue

模板

<template>
  <div id="app">
      <transition :name="transition">
          <keep-alive>
              <router-view v-if="$route.meta.keepAlive"></router-view>
          </keep-alive>
      </transition>
      <transition :name="transition">
          <router-view v-if="!$route.meta.keepAlive"></router-view>
      </transition>
  </div>
</template>

js

<script>
export default {
  name: "App",
  data() {
    return {
      transition: ""
    };
  },
  created(){
    var uid = this.$route.query.uid;
        uid = uid ? uid : 1;
    this.my.setSession(‘tbk_uid‘,uid);
  },
  watch: {
    $route(to, from) {
      if (to.meta.index > from.meta.index) {
        this.transition = "slide-left";
      } else {
        this.transition = "slide-right";
      }
    }
  },
}
</script>

样式

.slide-right-enter-active,
.slide-right-leave-active,
.slide-left-enter-active,
.slide-left-leave-active {
  will-change: transform;
  transition: all 500ms;
  position: absolute;
  width:100%;
  height:100%;
}
.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);
}

以上是关于vue 页面过渡效果的主要内容,如果未能解决你的问题,请参考以下文章

vue 页面过渡效果

vue列表过渡效果

Vue版本过渡变化

vue过渡效果之--javascript钩子

Vue仿微信app页面跳转动画

Vue_(组件)过渡效果