javascript - Vue 3 – 淡入淡出过渡

标签 javascript fade vuejs3

然而,我阅读了 Vue 2 的转换更改并阅读了 Vue 3 文档,但我仍然无法弄清楚如何使转换工作。 我对 Vue 很陌生。
旧页面应该淡出,新页面应该淡入,但我无法让它工作。
我真的不知道在 <transition> 里面写什么包装器而不是默认组件。我尝试将组件更改为 View 的名称,但这不起作用。
我的 App.vue

<router-view :key="route.path" v-slot="{Component}" />
  <transition name="fade" mode="out-in">
    <component :is="Component" />
  </transition>
</router-view>
我的 CSS:
.fade-enter-active,
.fade-leave-active {
  transition: opacity 1s ease;
}

.fade-enter-from,
.fade-leave-active {
  opacity: 0;
}
我的文件夹结构:
Components: – Header.vue
  |         - Footer.vue
  |
Views:      - Home.vue
            - About.vue
            - Something.vue
感谢您提供有关如何使淡入淡出工作的任何提示!

最佳答案

尝试使用 .fade-leave-to反而:

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.com/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>

使用您的代码段的示例:
<router-view v-slot="{ Component }">
    <transition name="fade" mode="out-in">
        <component :is="Component" />
    </transition>
</router-view>
.fade-enter-active,
.fade-leave-active {
    transition: opacity 1s ease;
}

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

关于javascript - Vue 3 – 淡入淡出过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65484166/

相关文章:

javascript - React JS 更改文本值并提交

javascript - jQuery 链接淡入淡出。帮助!

javascript - 无法让 Vue 3 子组件正确识别 prop 数据

javascript - "path"参数必须是字符串类型或 Buffer 或 URL cloudinary 和 nodejs 的实例

javascript - 谷歌地图自动完成功能不起作用 我该如何解决这个问题?

javascript - Jquery 悬停淡入淡出缩略图

javascript - 重置子组件的 v-model

vue.js - Vue3 在 vi​​test 中使用 vuex 测试组合 API

javascript - JavaScript 中的对象原型(prototype)

jQuery : crossfading image on hover