vue路由的页面

        <router-view v-slot="{Component}">
            <keep-alive>
                <transition :name="animation">
                    <component :is="Component" />
                </transition>
            </keep-alive>
        </router-view>

动画样式

.slide-left-enter-active,
.slide-left-leave-active,
.slide-right-enter-active,
.slide-right-leave-active {
	width: 100%;
    height: 100%;
    will-change: transform;
    transition: all 300ms cubic-bezier(.55,0,.1,1);
    position: absolute;
    backface-visibility: hidden;
}
.slide-right-enter-active {
    opacity: 0;
    transform: translate3d(-100%, 0, 0);
}
.slide-right-leave-active {
    opacity: 0;
    transform: translate3d(3%, 0, 0);
}
.slide-left-enter-active{
    opacity: 0;
    transform: translate3d(100%, 0, 0);
}
.slide-left-leave-active{
    opacity: 0;
    transform: translate3d(-3%, 0, 0);
}

引入onBeforeRouteUpdate

import {onBeforeRouteUpdate} from 'vue-router';

setup(){
    const animation = ref('slide');
    onBeforeRouteUpdate((to,form)=>{
	    if(to.meta.index > form.meta.index){
		    animation.value = 'slide-left'
	    }else{
		    animation.value = 'slide-right'
	    }
    })
    return {
        animation
    }
}

router.js设置 meta:{index:1}

{
        path: '/home',
        name: '首页',
        component: () => import('../views/Home.vue'),
		children:[{
	        path: '/onlineNum',
	        name: '在线人数',
	        component: () => import('../views/pages/Online.vue'),
			meta:{index:1}
		},{
	        path: '/company',
	        name: '单位列表',
	        component: () => import('../views/pages/Company.vue'),
			meta:{index:2}
		}]
}

Logo

前往低代码交流专区

更多推荐