18

I am trying to create some transitions on my router-view components every time I click a new link. The problem is that only one of the fade animations will work. For example, it will fade out, but the new page will appear immediately like normal. Basically I can only have either an enter-active-class or a leave-active-class, but not both at the same time.

<template>

    <div class="tom-layout">
        <navBar class="z-depth-0"></navBar>
        <div class="content-layout">
            <transition name="fade">
                <router-view></router-view>
            </transition>
        </div>
    </div>

</template>

<script>
    import NavBar from './components/NavBar.vue';

    export default {
        components: {
            navBar: NavBar
        }
    }

</script>

<style lang="scss">
    @import url('https://fonts.googleapis.com/css?family=Ek+Mukta');

    body {

        overflow: hidden;

        .content-layout {
            margin-top: -64px;
            width: 100%;
            z-index: -5;
        }
    }   


.fade-enter {
    opacity: 0;
}

.fade-enter-active {
    transition: opacity 2s ease;
}

.fade-leave {

}

.fade-leave-active {
    transition: opacity 2s ease;
    opacity: 0;
}

2 Answers 2

34

I am just using mode: out-in it seems to working fine with:

  <transition name="fade" mode="out-in">
    <router-view></router-view>
  </transition>

Please check working fiddle.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. This fixes the issue. Another solution I found was to add a transition-delay to .fade-enter-active with the same duration as the transition. .fade-enter-active { transition: opacity 0.25s ease; transition-delay: 0.25s; }
0

you can try dynamic binding for routing transition:

<router-view :transition="$route.transition">
And set the data of transition from your route data

router.map({
  '/About': {
    component: { ... },
    transition: 'slide'
  }
})

1 Comment

router.map has been replaced with array literals. vuejs.org/v2/guide/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.