当插槽中的数据在NUXT3/VUE3上更改时,如何使用过渡

发布于 2025-02-12 08:46:52 字数 2429 浏览 0 评论 0原文

我似乎无法将我的应用程序在路由更改上过渡,因为我使用的是默认布局,并且每个路线都是相同的。我希望插槽中的内容随着路线的变化而过渡,而不必重新加载/过渡。

布局/default.vue

<template>
    <div class="bg-darkSecondary dark:bg-black h-screen">
        <teleport to="body">
            <transition name="modal-fade">
                <div v-if="uiStore.functionLoading" class="modal-backdrop">
                    <UiBaseSpinner></UiBaseSpinner>
                </div>
            </transition>
        </teleport>
        <UiNav class="dark:bg-darkBg dark:text-darkSecondary" />
        <div class="flex dark:bg-black bg-darkSecondary">
            <transition name="sidebar" mode="out-in">
                <UiSideNav v-if="uiStore.sidebar" />
            </transition>
            <transition name="fade" mode="out-in">
                <div
                    v-if="!uiStore.appLoading"
                    class="flex-grow max-w-full max-h-full bg-darkSecondary dark:bg-black trans"
                >
                    <transition name="fade" mode="out-in" appear>
                        <div>
                            <slot />
                        </div>
                    </transition>
                </div>
                <div v-else class="flex flex-grow mt-40 justify-center trans">
                    <UiBaseSpinner />
                </div>
            </transition>
        </div>
        <UiFooter class="fixed bottom-0" />
    </div>
</template>

我专门试图获取以下插槽以每次在其中的数据进行过渡时进行过渡,例如,如果我要更改路由,则插槽中的内容将会更改,但是我无法理解如何应用tranisition,因为从技术上讲什么都没有被删除,如果我没记错的话,插槽只会用不同的数据呈现。

布局/默认值

<transition name="fade" mode="out-in">
    <div v-if="!uiStore.appLoading" class="flex-grow max-w-full max- 
       h-full bg-darkSecondary dark:bg-black trans">
            <transition name="fade" mode="out-in" appear>
                <div>
                    <slot />
                </div>
            </transition>
        </div>
        <div v-else class="flex flex-grow mt-40 justify-center 
         trans">
            <UiBaseSpinner />
        </div>
</transition>

I cannot seem to get my app to transition on a route change because I am using a default layout and this is the same for each route. I want the content within the slot to transition as the routes change without the layout having to be reloaded/transitioned as well.

layouts/default.vue

<template>
    <div class="bg-darkSecondary dark:bg-black h-screen">
        <teleport to="body">
            <transition name="modal-fade">
                <div v-if="uiStore.functionLoading" class="modal-backdrop">
                    <UiBaseSpinner></UiBaseSpinner>
                </div>
            </transition>
        </teleport>
        <UiNav class="dark:bg-darkBg dark:text-darkSecondary" />
        <div class="flex dark:bg-black bg-darkSecondary">
            <transition name="sidebar" mode="out-in">
                <UiSideNav v-if="uiStore.sidebar" />
            </transition>
            <transition name="fade" mode="out-in">
                <div
                    v-if="!uiStore.appLoading"
                    class="flex-grow max-w-full max-h-full bg-darkSecondary dark:bg-black trans"
                >
                    <transition name="fade" mode="out-in" appear>
                        <div>
                            <slot />
                        </div>
                    </transition>
                </div>
                <div v-else class="flex flex-grow mt-40 justify-center trans">
                    <UiBaseSpinner />
                </div>
            </transition>
        </div>
        <UiFooter class="fixed bottom-0" />
    </div>
</template>

I am specifically trying to get the below slot to have a transition everytime the data cheanges within it, example is if I were to change routes then the content within the slot will change, but i cannot understand how to apply a tranisition because nothing is technically being removed fro the DOM the Slot is just be rendered with difrerent data if I am not mistaken.

layouts/default.vue

<transition name="fade" mode="out-in">
    <div v-if="!uiStore.appLoading" class="flex-grow max-w-full max- 
       h-full bg-darkSecondary dark:bg-black trans">
            <transition name="fade" mode="out-in" appear>
                <div>
                    <slot />
                </div>
            </transition>
        </div>
        <div v-else class="flex flex-grow mt-40 justify-center 
         trans">
            <UiBaseSpinner />
        </div>
</transition>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

焚却相思 2025-02-19 08:46:52

我只是意识到如何做到这

<transition name="fade" mode="out-in" appear>
  <div :key="$route.path">
    <slot />
  </div>
</transition>

I just realized how to do this you can add a :key="$route.path" to a div that contains the slot like below

<transition name="fade" mode="out-in" appear>
  <div :key="$route.path">
    <slot />
  </div>
</transition>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文