admin管理员组文章数量:1426105
I am generating a simple static page with a list of ponents and when I visit the page from another page it renders everything correctly. When I land directly on the page some of the ponents 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
I am generating a simple static page with a list of ponents and when I visit the page from another page it renders everything correctly. When I land directly on the page some of the ponents 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
Share Improve this question asked Feb 11, 2021 at 10:27 Alessio ChiffiAlessio Chiffi 1412 silver badges12 bronze badges 9- seems like <Modal v-show="this.$store.state.modal.active" :id="this.$store.state.modal.id" /> Model after the footer is causing this issue. Since you are using vuex state, if you refresh then the data wont be persisted. log the this.$store.state.modal.active and check it out. – Lohith Commented Feb 11, 2021 at 10:31
- 1 thanks for the ment @Lohith, I think it makes sense. How would you approach the modal? Shall I include it in the ponent and not at the page level? – Alessio Chiffi Commented Feb 11, 2021 at 10:37
- If the problem is really uncontrolled state data, then you can keep default value in data(){modalActive:false} , update the value with mapState, then refer modalActive in the template. – Lohith Commented Feb 11, 2021 at 10:40
- 1 I am removing the modal functionality for now to check if it still has the issue. I will keep you posted but looks like it's related to the state data as you mentioned. One more thing I have noticed is that it works fine when I run it locally and the issue is only when it gets generated – Alessio Chiffi Commented Feb 11, 2021 at 11:00
- 1 hey @Lohith confirming that was a vuex issue. I've spotted the ponent and wrapped it with a client-only tag and it fixed the issue. thx for your help – Alessio Chiffi Commented Feb 12, 2021 at 9:16
1 Answer
Reset to default 6Issue is with vuex state management when running it as static site. which works proper when running in the develop mode.
Ways to overe this is.
- avoiding the direct call to state variables in the template.
- making use of
client-only
tag which helps to avoid dom-mismatch issue.
本文标签: javascriptNuxt jsSSR page duplicates componentsStack Overflow
版权声明:本文标题:javascript - Nuxt js - SSR page duplicates components - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745468663a2659647.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论