<template>
<transition :name="transitionName">
<router-view class="child-view"></router-view>
</transition>
</template>
<script>
export default {
data () {
return {
transitionName: 'slide-right'
}
},
watch: {
$route (to, from) {
const toDepth = to.path.split('/').length
const fromDepth = from.path.split('/').length
this.transitionName = toDepth < fromDepth ? 'slide-right' : 'slide-left'
}
}
}
</script>
<style>
.child-view {
transition: all 0.3s cubic-bezier(0.55, 0, 0.1, 1);
transition-delay: 0.1s
}
.slide-left-enter,
.slide-right-leave-active {
opacity: 0;
-webkit-transform: translate(30px, 0);
transform: translate(30px, 0);
}
.slide-left-leave-active,
.slide-right-enter {
opacity: 0;
-webkit-transform: translate(-30px, 0);
transform: translate(-30px, 0);
}
网友评论