app.vue 1.62 KB
<template>
  <div id="app">
    <transition
      :name="`route-view-${yoho.direction}`">
      <keep-alive>
        <router-view v-if="$route.meta.keepAlive"></router-view>
      </keep-alive>
    </transition>
    <transition
      :name="`route-view-${yoho.direction}`">
      <router-view v-if="!$route.meta.keepAlive"></router-view>
    </transition>
  </div>
</template>

<script>
import {mapState} from 'vuex';

export default {
  name: 'App',
  computed: {
    ...mapState(['yoho'])
  },
  mounted() {
    if (this.yoho.context.needLogin) {
      this.$yoho.ready(() => {
        this.$sdk.goLogin();
      });
    }
  },
  watch: {
    'yoho.context.needLogin': function(newVal) {
      if (newVal) {
        this.$sdk.goLogin();
      }
    },
  }
};
</script>

<style lang="scss">
.route-view-forword-enter-active,
.route-view-forword-leave-active,
.route-view-back-enter-active,
.route-view-back-leave-active {
  will-change: true;
  width: 100%;
  height: 100%;
  position: absolute;
  backface-visibility: hidden;
  perspective: 1000;
}

.route-view-forword-leave-active,
.route-view-back-leave-active {
  transition: all 200ms;
}

.route-view-forword-enter-active,
.route-view-back-enter-active {
  transition: all 200ms cubic-bezier(0.165, 0.84, 0.44, 1);
}

.route-view-forword-enter {
  transform: translate3d(100%, 0, 0);
}

.route-view-forword-enter-active {
  z-index: 2;
}

.route-view-forword-leave-active {
  z-index: -1;
  transform: translate3d(-30%, 0, 0);
}

.route-view-back-enter {
  z-index: -1;
  transform: translate3d(-30%, 0, 0);
}

.route-view-back-leave-active {
  transform: translate3d(100%, 0, 0);
  z-index: 2;
}
</style>