<template>
<div id="app" class="Router">
<transition :name="transitionName">
<router-view></router-view>
</transition>
</div>
</template>
<script>
export default {
name: 'App',
data() {
return {
transitionName:''
}
},
watch: {
$route(to, from) {
if(to.meta.index > from.meta.index) {
this.transitionName = 'slide-left';
}else{
this.transitionName = 'slide-right';
}
}
}
}
</script>
<style lang="scss">
#app{
width: 100%;
height: 100%;
}
.Router{
position: relative;
}
.Router>*{
position: absolute;
width: 100%;
}
.slide-right-enter-active,
.slide-right-leave-active,
.slide-left-enter-active,
.slide-left-leave-active {
will-change: transform;
transition: all 1500ms;
position: absolute;
}
.slide-right-enter {
opacity: 0;
transform: translate3d(-100%, 0, 0);
}
.slide-right-leave-active {
opacity: 0;
transform: translate3d(100%, 0, 0);
}
.slide-left-enter {
opacity: 0;
transform: translate3d(100%, 0, 0);
}
.slide-left-leave-active {
opacity: 0;
transform: translate3d(-100%, 0, 0);
}
</style>
import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
import route from './route'
const routes = [
{
path: '/',
name: 'login',
component: () => import('@/views/login'),
meta:{
index:1
}
},
{
path: '/detail',
name: 'detail',
component: () => import('@/views/login/detail'),
meta:{
index:2
}
},
{
path: '/city',
name: 'city',
component: () => import('@/views/login/city'),
meta:{
index:1
}
},
...route
]
const router = new VueRouter({
routes
})
export default router