:parent路由器视图上的关键属性,原因(out)在嵌套路由器视图中失败(out)过渡
预期的是,
我的一个视图中有一个选项卡式导航,该视图触发了将显示要显示的路由器视图
。对于这些嵌套路线,我想应用褪色过渡。我希望通过mode
in-in-in
进行过渡,以便旧的路由器视图
首先逐渐淡出,然后新的在。
查看在没有过渡的情况下消失,但是新的>根据需要逐渐消失。
当我删除:key =“ $ oute.fullpath”
parent router-view
in app.vue
(见下文),,嵌套过渡效果很好。但是,由于我重新使用路由器组件,因此我绝对需要一个键
属性 router-view 。
您还应该知道,如果没有出现
属性,abot-alive
围绕嵌套的路由器 - 视图
根本不会发生过渡。到目前为止,我根据此问题在github上。
我如何在路由器视图
in app.vue
中保留键
工作?
app.vue
<div class="main-wrapper">
<router-view :key="$route.fullPath" />
</div>
profile.vue(应该发生嵌套过渡的地方)
<div class="profile__main">
<router-view v-slot="{ Component }">
<Transition name="fade" mode="out-in" appear>
<keep-alive>
<component :is="Component"></component>
</keep-alive>
</Transition>
</router-view>
</div>
[...]
.fade-enter-from, .fade-leave-to {
opacity: 0;
}
.fade-leave-active {
transition-duration: 500ms;
transition-property: all;
transition-timing-function: ease;
}
.fade-enter-active {
transition-duration: 300ms;
transition-property: all;
transition-timing-function: ease;
}
路由器/index.js
{
path: '/profile',
name: 'Profile',
component: Profile,
meta: {
requiresAuth: true,
title: 'Your Profile',
},
children: [
{
path: '',
name: 'ProfileOverview',
component: ProfileOverview,
},
{
path: 'settings',
name: 'ProfileSettings',
component: ProfileSettings,
meta: {
title: 'Your Profile Settings',
},
},
{
path: 'subscriptions',
name: 'ProfileSubscriptions',
component: ProfileSubscriptions,
meta: {
title: 'Your Subscriptions',
},
}]
},
What is expected
I have a tabbed navigation in one of my views which triggers nested router-views
to be displayed. For these nested routes I want to apply a fade transition. I expect the transition to happen with mode
out-in
, so that the old router-view
first fades out and then the new one fades in.
What is happening
Only the in transition of the out-in
mode
works: When clicking on a navigation tab the old router-view
disappears without transition, but the new one fades in as desired.
When I remove the :key="$route.fullPath"
attribute of the parent router-view
in App.vue
(see below), the nested transitions work fine. But since I re-use router components I definitely need a key
attribute on my outer router-view
.
Also you should know that without the appear
attribute and the keep-alive
around the nested router-view
no transition would happen at all. I adjusted my code so far according to this issue on GitHub.
How can I manage to both keep the key
on the router-view
in App.vue
and make the transition in the nested view work?
App.vue
<div class="main-wrapper">
<router-view :key="$route.fullPath" />
</div>
Profile.vue (where nested transitions should happen)
<div class="profile__main">
<router-view v-slot="{ Component }">
<Transition name="fade" mode="out-in" appear>
<keep-alive>
<component :is="Component"></component>
</keep-alive>
</Transition>
</router-view>
</div>
[...]
.fade-enter-from, .fade-leave-to {
opacity: 0;
}
.fade-leave-active {
transition-duration: 500ms;
transition-property: all;
transition-timing-function: ease;
}
.fade-enter-active {
transition-duration: 300ms;
transition-property: all;
transition-timing-function: ease;
}
router/index.js
{
path: '/profile',
name: 'Profile',
component: Profile,
meta: {
requiresAuth: true,
title: 'Your Profile',
},
children: [
{
path: '',
name: 'ProfileOverview',
component: ProfileOverview,
},
{
path: 'settings',
name: 'ProfileSettings',
component: ProfileSettings,
meta: {
title: 'Your Profile Settings',
},
},
{
path: 'subscriptions',
name: 'ProfileSubscriptions',
component: ProfileSubscriptions,
meta: {
title: 'Your Subscriptions',
},
}]
},
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了可能与您有关的类似问题。在我的情况下,我使用
&lt; suspense&gt;
与异步页/组件,并且仅过渡。因此,我想保持旧组件可见,直到准备好了,然后进行过渡。问题是,在&lt; router-view&gt;
旧页面上使用唯一时,旧页面正在立即消失,但有空白(或指定的悬念后备),最后过渡到新页面开始。没有
键
过渡,它像我想要的那样工作,因此页面之间没有空白/后备。无论如何,我对此进行了描述,以便有人可以谷歌搜索。
快速解决方案在这里: https://github.com/vuejs/vuejs/router/router/1175
因此,如果我们使用插槽中的组件,则应在该组件上而不是路由器视图上。
因此,请尝试以下操作:
I had similiar issue that could be related to yours. In my case I'm using
<Suspense>
with async pages/components and only out transition. So I wanted to keep old component visible until new one is ready, and then perform transition. Problem was that while using uniquekey
on<router-view>
old page was disappearing right away, then there was blank space (or specified Suspense fallback), and finally transition to new page started. Withoutkey
transition it was working like I wanted, so no blank/fallback between pages.Anyway, I described this so someone could google it.
Quick solution is here: https://github.com/vuejs/router/issues/1175
So if we use component from slot, key should be on that component and not router view.
So try this: