最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Vue 3 – fade transition broken - Stack Overflow

programmeradmin4浏览0评论

I read about the transition changes from Vue 2 however and read the Vue 3 docs but I still can't figure out how to make the transition work. I'm very new to Vue.

The old page should fade out and the new page should fade in, I can't get it to work though.

I don't really know what to write inside the <transition> wrapper other than the default ponent. I tried changing ponent to the views' names but that doesn't work.

My App.vue

<router-view :key="route.path" v-slot="{Component}" />
  <transition name="fade" mode="out-in">
    <ponent :is="Component" />
  </transition>
</router-view>

My CSS:

.fade-enter-active,
.fade-leave-active {
  transition: opacity 1s ease;
}

.fade-enter-from,
.fade-leave-active {
  opacity: 0;
}

My folder structure:

Components: – Header.vue
  |         - Footer.vue
  |
Views:      - Home.vue
            - About.vue
            - Something.vue

Thanks for any tips on how to make the fade work!

I read about the transition changes from Vue 2 however and read the Vue 3 docs but I still can't figure out how to make the transition work. I'm very new to Vue.

The old page should fade out and the new page should fade in, I can't get it to work though.

I don't really know what to write inside the <transition> wrapper other than the default ponent. I tried changing ponent to the views' names but that doesn't work.

My App.vue

<router-view :key="route.path" v-slot="{Component}" />
  <transition name="fade" mode="out-in">
    <ponent :is="Component" />
  </transition>
</router-view>

My CSS:

.fade-enter-active,
.fade-leave-active {
  transition: opacity 1s ease;
}

.fade-enter-from,
.fade-leave-active {
  opacity: 0;
}

My folder structure:

Components: – Header.vue
  |         - Footer.vue
  |
Views:      - Home.vue
            - About.vue
            - Something.vue

Thanks for any tips on how to make the fade work!

Share Improve this question asked Dec 28, 2020 at 21:14 AnnaAnna 1211 silver badge8 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

Try using .fade-leave-to instead:

Vue.createApp({
  setup() {
    const test = Vue.ref(false);
    
    return { test }
  }
}).mount('#app')
.fade-enter-active,
.fade-leave-active {
  transition: opacity 1s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}
<script src="https://unpkg./vue@next"></script>

<div id="app">
  <transition name="fade" mode="out-in">
    <div v-if="test">FADE</div>
  </transition>
  <button @click="test = !test">TOGGLE</button>
</div>

Example using your snippet:

<router-view v-slot="{ Component }">
    <transition name="fade" mode="out-in">
        <ponent :is="Component" />
    </transition>
</router-view>
.fade-enter-active,
.fade-leave-active {
    transition: opacity 1s ease;
}

.fade-enter-from,
.fade-leave-to {
    opacity: 0;
}
发布评论

评论列表(0)

  1. 暂无评论