I have a spa vue page with vuetify, and when I change between the components of the aplication I want the component shows with a transition.
I tried with the <v-slide-y-transition>
tag and the transition="slide-y-transition
attribute but nothing works. Here some examples of what I tried:
Example with the "vuetify tag":
<template>
<v-app>
<v-slide-y-transition>
<h1>Test</h1>
</v-slide-y-transition>
</v-app>
</template>
Example with the attribute:
<template>
<v-app>
<div transition="slide-y-transition">
<h1>Test</h1>
</div>
</v-app>
</template>
The Vuetify transitions as you have them only work on the Vuetify library components. e.g. <v-menu transition="slide-x-transition">
where v-menu
is one of the components. You can't use the transitions that way on a simple <div>
.
However, Vue.js itself supports transitions using the following format.
<transition name="slide">
<div> element you are apply the transition to</div>
</transition>
You will have to define the css for the transition as per the documentation here. or you can use a css library like Animate.css
Example css from documentation:
.slide-fade-enter-active {
transition: all .3s ease;
}
.slide-fade-leave-active {
transition: all .8s cubic-bezier(1.0, 0.5, 0.8, 1.0);
}
.slide-fade-enter, .slide-fade-leave-to {
transform: translateX(10px);
opacity: 0;
}
In case someone needs to know how to use VuetifyJS transitions with router-view
which I understood by page transitions.
router-view
TransitionsHere you can use the Vuetify transitions directly
<v-main>
<v-container fill-height>
<v-slide-x-transition mode="out-in">
<router-view />
</v-slide-x-transition>
</v-container>
</v-main>
In Vue3 / Vuetify3 this is unfortunately no longer directly usable due to the changes in the router-view API. But of course you can pick the values of the Vuetify transitions on Github and recreate them accordingly.
<template>
<v-main>
<v-container fill-height>
<router-view v-slot="{ Component, route }">
<transition name="slide-x" mode="out-in">
<component :is="Component" :key="route.path" />
</transition>
</router-view>
</v-container>
</v-main>
</template>
<style>
/* v-slide-x-transition look a like */
.slide-x-enter-active,
.slide-x-leave-active {
transition: transform .6s cubic-bezier(0.25, 0.8, 0.5, 1), opacity .8s;
opacity: 1;
}
.slide-x-enter-from,
.slide-x-leave-to {
opacity: 0;
}
.slide-x-enter-from {
transform: translateX(100px);
}
.slide-x-leave-to {
transform: translateX(-100px);
}
</style>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With