vue實(shí)現(xiàn)app頁面切換動(dòng)畫效果

因?yàn)樾枰獙?shí)現(xiàn)類似APP頁面切換的動(dòng)畫效果,百度google搜索比較少資料,所以自己寫文檔,希望對(duì)您有用

Paste_Image.png

在router/index.js

import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

Router.prototype.goBack = function () {
  this.isBack = true
  window.history.go(-1)
}
const router = new Router({
  routes: [
    {
      path: '/',
      name: 'PageTransition', 
      component: PageTransition, // 引入頁面切換組件
      children: [{
        path: '',
        component: Index  // 父路由訪問頁面,例如,訪問www.aaa.com/ 顯示的是Index組件
      }, {
        path: '/pageA',
        component: PageA  // 子路由組件  例如,訪問www.aaa.com/pageA 顯示為PageA
      }, {
        path: '/pageB',
        component: PageB // 子路由組件  例如,訪問www.aaa.com/pageB 顯示為PageB
      }]
    }
  ]
})

監(jiān)聽路由變化

在放置 <router-view>的vue文件中

//templete    
<transition name='transitionName' keep-alive>
        <router-view></router-view>
    </transition>

//script
    beforeRouteUpdate(to,from,next){
        let isBack = this.$router.isBack;
        if( isBack ){
            this.transitionName = 'slide-right'
        }else{
            this.transitionName = 'slide-left'
        }
        this.$router.isBack = false;
    }
//style
.slide-left-enter, .slide-right-leave-active {
  opacity: 0;
  -webkit-transform: translate(50px, 0);
  transform: translate(50px, 0);
}
.slide-left-leave-active, .slide-right-enter {
  opacity: 0;
  -webkit-transform: translate(-50px, 0);
  transform: translate(-50px, 0);
}

在需要點(diǎn)擊返回的按鈕中設(shè)置 goback

<div class="left" @click="goback"><</div>

methods: {
    goback () {
      this.$router.goBack()
    }
  }

我自己的github地址 https://github.com/Jaction/page-app-Ainimate
大牛的github地址https://github.com/zhengguorong/pageAinimate

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • 這是Ruifree的自媒體平臺(tái)分享的第2篇原創(chuàng)文章,圖片來自Gratisography 很多人都有這樣的感受,生活...
    空山歆語閱讀 316評(píng)論 0 0
  • 中國(guó)人都喜歡拉關(guān)系,有關(guān)系,萬事好辦!這個(gè)觀念也很容易理解,畢竟我們從出生開始,從有自我意識(shí)開始,就開始與周遭建立...
    JforJoker閱讀 437評(píng)論 3 3