简体   繁体   English

Nuxt js - SSR 页面重复组件

[英]Nuxt js - SSR page duplicates components

I am generating a simple static page with a list of components and when I visit the page from another page it renders everything correctly.我正在生成一个带有组件列表的简单 static 页面,当我从另一个页面访问该页面时,它会正确呈现所有内容。 When I land directly on the page some of the components are rendered again after the footer.当我直接登陆页面时,一些组件在页脚之后再次呈现。 If I inspect the element I can see that they are the same elements but rendered again after the footer.如果我检查元素,我可以看到它们是相同的元素,但在页脚之后再次呈现。 Anyone has any idea on why this is happening?任何人都知道为什么会这样?

<template>
  <div>
    <client-only>
      <MobileNav v-if="!isDesktop" />
      <Topnav v-if="isDesktop" />
      <div v-if="isDesktop">
        <Navbar active-page="consumers" />
      </div>
    </client-only>
    <Hero page="consumers" hero-text="for consumers" text-alignment="middle" />
    <AnchorNav :anchor-nav-items="anchorNavData" />

    <div id="for-consumers">
      <Highlight :data="highlight1" />
      <Highlight :data="highlight2" />
    </div>

    <LazyCardsWithModal :data="cardsList" />

    <LazyImageText :data="imageTextDirector" />

    <LazyKeyCards :data="keyCards" />

    <LazyAccordion :data="accordionData" />

    <LazyOrderedList :data="orderedList" />

    <LazyLogoCards :data="logoCards" :index="1" />
    <LazyLogoCards :data="logoCards2" :index="2" />

    <LazyCardsWithModal :data="productsCards" class="consumers-cards-2" />

    <Footer />

    <Modal
      v-show="this.$store.state.modal.active"
      :id="this.$store.state.modal.id"
    />
  </div>
</template>

This is what the page template looks like这是页面模板的样子

Issue is with vuex state management when running it as static site.当作为 static 站点运行时,问题在于 vuex state 管理。 which works proper when running in the develop mode.在开发模式下运行时可以正常工作。

Ways to overcome this is.克服这一点的方法是。

  1. avoiding the direct call to state variables in the template.避免在模板中直接调用 state 变量。
  2. making use of client-only tag which helps to avoid dom-mismatch issue.使用client-only标签有助于避免 dom 不匹配问题。

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

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