源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

vue实现app页面切换动画效果实例

  • 时间:2020-04-25 14:05 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:vue实现app页面切换动画效果实例
因为需要实现类似APP页面切换的动画效果,百度google搜索比较少资料,所以自己写文档,希望对您有用 [img]http://files.jb51.net/file_images/article/201705/2017523110210059.png?201742311226[/img] 在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
   }]
  }
 ]
})

[b]监听路由变化[/b] 在放置 <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);
}
在需要点击返回的按钮中设置 goback
<div class="left" @click="goback"><</div>

methods: {
  goback () {
   this.$router.goBack()
  }
 }
我自己的github地址 [url=https://github.com/Jaction/page-app-Ainimate]https://github.com/Jaction/page-app-Ainimate[/url] 大牛的github地址[url=https://github.com/zhengguorong/pageAinimate]https://github.com/zhengguorong/pageAinimate[/url] 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程素材网。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部