Ulukbek Abylbekov
Ulukbek Abylbekov

Reputation: 459

My vuejs animation/transition is lagging on path change.

enter image description here

I am using vue and vue-router for my portfolio. I added simple "fade" animation. And my animation is lagging.

My App.vue component:

<template>
    <div id="app">
        <Square/>
        <Navbar/>
    </div>
</template>

My Square.vue component:

<template>
    <div id="square">
        <transition name="fade">
            <router-view></router-view>
        </transition>
    </div>
</template>
<style>
    .fade-enter-active, .fade-leave-active {
      transition: opacity 0.5s;
    }
    .fade-enter, .fade-leave-to{
      opacity: 0;
    }
 </style>

My routes file:

import Vue from 'vue';
import Router from 'vue-router';
import Hello from './views/Hello.vue';

Vue.use(Router);

export default new Router({
  routes: [
    {
      path: '/',
      name: 'hello',
      component: Hello,
    },
    {
      path: '/i-am',
      name: 'I am',
      component: () => import( 
'./views/About.vue'),
    },
    {
      path: '/i-use',
      name: 'I use',
      component: () => import( 
'./views/Using.vue'),
    },
   ],
});

This is project structure

And I think it is not because of the style of animation. New content renders faster than old component destroys.

Upvotes: 2

Views: 3711

Answers (1)

keysl
keysl

Reputation: 2167

VueJS Transition Component has this cool props called mode. This will add a smooth effect upon destroying the previous component.

<transition name="fade" mode="out-in">
  <!-- ... the buttons ... -->
</transition>

https://v2.vuejs.org/v2/guide/transitions.html#Transition-Modes

Upvotes: 6

Related Questions