How to create Vue router transitions
In this post we will give you information about How to create Vue router transitions. Hear we will give you detail about How to create Vue router transitionsAnd how to use it also give you demo for it if it is necessary.
we are going to learn about how to create transitions between routes in our vue app.
Vue.js provides us a <transistion> component by wrapping that component with <router-view> we can easily add transitions to routes.
Note: This tutorial assumes that you already familiar with Vue transitions. If you don’t know about how transitions work in Vue then check out Intro to Vue.js transitions
<template> <div id="app"> <ul> <router-link to="/">Home</router-link> <router-link to="/user">User</router-link> <router-link to="/contact">Contact us</router-link> </ul> <transition> <router-view /> </transition> </div></template><script>export default {};</script>
In the above example, we wrapped our <router-view> component with <transistion> component but still we didn’t see any transitions because we need to add a name attribute with transition class name to <transistion> component.
Slide transition example
<template> <div id="app"> <ul> <router-link to="/">Home</router-link> <router-link to="/user">User</router-link> <router-link to="/contact">Contact us</router-link> </ul> <transition name="slide" mode="out-in"> <router-view /> </transition> </div></template><script>export default {};</script><style>/*slide transition*/<span>.slide-enter-active,.slide-leave-active { transition: transform 0.4s ease-out;}.slide-enter { transform: translateX(-30%);}<span>.slide-leave-to { transform: translateX(30%);}</style>
Here we also added mode=’out-in’ attribute where out-in means the old component is removed first before adding a new component.
Flip transition example
Let’s add a flip transition effect to our routes by removing slide transition.
<template> <div id="app"> <ul> <router-link to="/">Home</router-link> <router-link to="/user">User</router-link> <router-link to="/contact">Contact us</router-link> </ul> <transition name="flip" mode="out-in"> <router-view /> </transition> </div></template><script>export default {};</script><style>/*flip transition*/.flip-enter-active,.flip-leave-active { transition: transform 0.3s ease-out;}.flip-enter { transform: rotateY(90deg);}<span>.flip-leave-to { transform: rotateY(90deg);}<span></style>
Hope this code and post will helped you for implement How to create Vue router transitions. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs