最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Nuxt layout rendering delay, content flashes - Stack Overflow

programmeradmin1浏览0评论

Using Nuxt 3, I'm switching from my "login" layout to my "admin" layout.

This works great except for one thing: When switching layouts, there are few milliseconds where the "admin page content" can be seen displayed within the "login" layout. This means I can see my "Admin homepage" displayed in the previous "login" layout.

I can clearly see this desync in the devtools using the performance tab, very clearly when throttling the CPU.

This is espacially annoying because this produces content flashes.

No data fetching is involved. I do not use animations.

Why does this happen? How can I properly handle layout changing?

I tried the following code to handle the layout change to no avail:

preloadComponents(['admin']).then(() => {
          setPageLayout('admin');
          return navigateTo(this.localePath('/admin'));
        });

Here are snippets of the codebase:

app.vue

<template>
  <NuxtLayout :name="layoutName">
    <NuxtPage />
  </NuxtLayout>
</template>

<script setup lang="ts">

function setLayout(fullPath: string) {
  switch (true) {
    case !!fullPath.match(/^\/\w{2}\/admin/g):
      layoutName.value = 'admin';
      break;
...
  }
}

watch(() => route.fullPath, setLayout, {immediate: true});

</script>

login.vue / admin.vue

<template>
  <div class="container-fluid px-0">
    <div>
      <div class="row">
         ...
      </div>
      <div class="container login-container">
        <slot></slot>
      </div>
    </div>
  </div>
</template>
发布评论

评论列表(0)

  1. 暂无评论