Vue-router combined with transition to achieve app forward and rewind animation transitions

Source: Internet
Author: User
Tags rewind

First configure the route and modify the routing configuration

路由配置就不讲了

VueRouter.prototype.goBack = function () {///focus, add a GoBack method to Vueroute to record the forward and backward state of the route This.isback = True
This.isback = True
Window.history.go (-1)
}

 
Monitoring Routing Changes

<template>
<div>
<transition:name= "Transitionname" >//Dynamic bound route animation
<router-view class= "Router" ></router-view>
</transition>
</div>
</template>

<script>
Export Default {
Data () {
return {
Transitionname: ' slide-right '//default dynamic route changed to Slide-right
}
},
Watch: {
' $route ' (to, from) {
Let Isback = this. $router. Isback// monitor the status of the route change to forward or backward
if (isback) {
This.transitionname = ' Slide-right '
} else {
This.transitionname = ' Slide-left '
}
this. $router. Isback = False
}
}
}
</script>

<style>
. Router {
Position:absolute;
width:100%;
Transition:all. 8s Ease;
top:40px;
}

. Slide-left-enter,
. slide-right-leave-active {
opacity:0;
-webkit-transform:translate (100%, 0);
Transform:translate (100%, 0);
}

. Slide-left-leave-active,
. slide-right-enter {
opacity:0;
-webkit-transform:translate (-100%, 0);
Transform:translate (-100% 0);
}
</style>

Route forward in the normal way to go on the line, back when the call GoBack method is ok

Vue-router combined with transition to achieve app forward and rewind animation transitions

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.