首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >vue移动端 实现手机左右滑动入场动画

vue移动端 实现手机左右滑动入场动画

作者头像
马克社区
发布2022-06-06 19:29:14
发布2022-06-06 19:29:14
2.4K0
举报
文章被收录于专栏:高端IT高端IT

app.vue

代码语言:javascript
复制
<template>
  <div id="app">
    <transition :name="transitionName">
      <keep-alive >
        <router-view v-if="$route.meta.keepAlive" class="Router"></router-view>
      </keep-alive>
    </transition >
    <transition :name="transitionName">
      <router-view v-if="!$route.meta.keepAlive"  class="Router"></router-view>
    </transition >
    <Play></Play>
  </div>
</template>
<script>import Play from './components/play'
export default {
  name: 'App',
  data () {
    return {
      transitionName: 'slide-left'
    }
  },
  watch: {
    '$route' (to, from) {
      // 切换动画
      let isBack = this.$router.isBack // 监听路由变化时的状态为前进还是后退
      if (isBack === true) {
        this.transitionName = 'slide-right'
        // from.meta.keepAlive = false
        // to.meta.keepAlive = true
      } else {
        // from.meta.keepAlive = true
        // to.meta.keepAlive = false
        // this.transitionName = 'slide-left'
        if (this.$route.path.split('/').length < 3) {
          this.transitionName = 'slide-fade'
        } else {
          this.transitionName = 'slide-left'
        }
      }
      this.$router.isBack = false
    }
  },
  components: {
    Play
     }
}
</script>

更多内容请见原文,原文转载自:https://blog.csdn.net/weixin_44519496/article/details/119353623

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档