当插槽中的数据在NUXT3/VUE3上更改时,如何使用过渡
我似乎无法将我的应用程序在路由更改上过渡,因为我使用的是默认布局,并且每个路线都是相同的。我希望插槽中的内容随着路线的变化而过渡,而不必重新加载/过渡。
布局/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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我只是意识到如何做到这
I just realized how to do this you can add a
:key="$route.path"
to a div that contains the slot like below