SoFunction
Updated on 2025-04-05

Vue-router How to enter and exit animation when switching component pages

Code

<template>

 <div >
 <Header></Header>
 // Use transition to include the container of the switch component page <transition name="slide-fade">
  <router-view></router-view>
 </transition>

 </div>
</template>



<script>
import Header from './components/header'
export default {
 name: 'app',
 components: {Header},

}

</script>
// Animation<style scoped>
.slide-fade{
 position: absolute;left:0;right: 0;
}
.slide-fade-enter-active {
 transition: all 1.2s ease;
}
.slide-fade-leave-active {

 transition: all .1s cubic-bezier(2.0, 0.5, 0.8, 1.0);
}
.slide-fade-enter, .slide-fade-leave-to
{
 left:0;right: 0;
 transform: translateX(50px);
 opacity: 0;
}
</style>

The above article on Vue-router's method of entering and exiting animations when switching component pages is all the content I share with you. I hope you can give you a reference and I hope you can support me more.