:parent路由器视图上的关键属性,原因(out)在嵌套路由器视图中失败(out)过渡

发布于 2025-02-03 04:39:14 字数 2210 浏览 5 评论 0原文

预期的是,

我的一个视图中有一个选项卡式导航,该视图触发了将显示要显示的路由器视图。对于这些嵌套路线,我想应用褪色过渡。我希望通过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 技术交流群。

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

发布评论

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

评论(1

檐上三寸雪 2025-02-10 04:39:15

我遇到了可能与您有关的类似问题。在我的情况下,我使用&lt; suspense&gt;与异步页/组件,并且仅过渡。因此,我想保持旧组件可见,直到准备好了,然后进行过渡。问题是,在&lt; router-view&gt; 旧页面上使用唯一时,旧页面正在立即消失,但有空白(或指定的悬念后备),最后过渡到新页面开始。没有过渡,它像我想要的那样工作,因此页面之间没有空白/后备。

无论如何,我对此进行了描述,以便有人可以谷歌搜索。

快速解决方案在这里: https://github.com/vuejs/vuejs/router/router/1175

因此,如果我们使用插槽中的组件,则应在该组件上而不是路由器视图上。

因此,请尝试以下操作:

<div class="profile__main">
  <router-view v-slot="{ Component }">
    <Transition name="fade" mode="out-in" appear>
      <component :is="Component" :key="$route.fullPath"></component>
    </Transition>
  </router-view>
</div>

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 unique key 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. Without key 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:

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