简体   繁体   English

Vue 3 中的 SSR 和 keep-alive 问题:动态组件

[英]SSR and keep-alive issue in Vue 3: dynamic component

<template>
      <div class="default-layout">
          <router-view v-slot="{ index }">
            <keep-alive>
              <component :is="index" :key="route.fullPath" />
            </keep-alive>
          </router-view> 
      </div>
</template>
    
<script lang="ts">
    import { defineComponent} from "vue";
    import { useRoute } from "vue-router";
    import Index from "@/pages/index";
    
    export default defineComponent({
      name: "app",
      components: {
        Index,
      },
      setup: () => {
        const route = useRoute();
       
        return { route, index: Index };
      },
    });

</script>

It will lead to an error while rendering:渲染时会报错:错误信息

[Vue warn]: Hydration node mismatch:
- Client vnode: Symbol(Comment) 
- Server rendered DOM: <!--[--> (start of fragment) 
  at <KeepAlive> 
  at <RouterView key=0 > 
  at <App>

Hydration children mismatch in <div>: server rendered element contains fewer child nodes than client vdom. 

Hydration completed but contains mismatches.

What shall I do to fix this issue?我该怎么做才能解决这个问题?

I believe this is a bug.我相信这是一个错误。 You can follow it at https://github.com/vuejs/vue-next/issues/4817你可以在https://github.com/vuejs/vue-next/issues/4817关注它

At the time of this writing, it was not yet confirmed by Vue maintainers.在撰写本文时,Vue 维护人员尚未确认。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM