最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - My vuejs animationtransition is lagging on path change. - Stack Overflow

matteradmin5PV0评论

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

My App.vue ponent:

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

My Square.vue ponent:

<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',
      ponent: Hello,
    },
    {
      path: '/i-am',
      name: 'I am',
      ponent: () => import( 
'./views/About.vue'),
    },
    {
      path: '/i-use',
      name: 'I use',
      ponent: () => import( 
'./views/Using.vue'),
    },
   ],
});

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

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

My App.vue ponent:

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

My Square.vue ponent:

<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',
      ponent: Hello,
    },
    {
      path: '/i-am',
      name: 'I am',
      ponent: () => import( 
'./views/About.vue'),
    },
    {
      path: '/i-use',
      name: 'I use',
      ponent: () => import( 
'./views/Using.vue'),
    },
   ],
});

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

Share Improve this question asked Nov 16, 2018 at 1:40 Ulukbek AbylbekovUlukbek Abylbekov 4591 gold badge6 silver badges21 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

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

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

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

Post a comment

comment list (0)

  1. No comments so far