首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何正确使用Nuxtjs中的悬念

如何正确使用Nuxtjs中的悬念
EN

Stack Overflow用户
提问于 2022-07-25 11:57:11
回答 1查看 465关注 0票数 2

我想在从API中获取或加载数据时使用skelton来代替carousel的数据,为此,我试图在我的Nuxtjs3页面中使用悬念。

但我无法让它发挥作用。

在下面的设置中,我没有得到任何东西来代替旋转木马。它的空白,即使承诺得到解决,如果我消除悬念,那么它运行良好。

这是我迄今所做的。

代码语言:javascript
复制
    <template>
        <div class="ttc-py-1 sm:ttc-py-5">
          <div class="ttc-container ttc-mx-auto">
            <SectionHeader :heading="`Activities near you`" />
            <client-only>
              <Carousel
                :items-to-show="3.5"
                :wrap-around="true"
                :breakpoints="breakpoints"
              >

                <Suspense>

                  <Slide
                    v-for="(item, index) in preferredTours"
                    :key="index"
                  >
                    <CardsActivityCard
                      :city="item.city"
                      :country="item.country"
                      :image="`${item.image}`"
                      :packagename="item.package_name"
                      :price="item.price"
                      :uniqueid="item.uniqueId"
                      :slug="item.slug"
                    />
                  </Slide>

                  <template #fallback>
                    <Slide v-for="i in 5" :key="i">
                      <div>loading ...... or Skeltons</div>
                    </Slide>
                  </template>

                </Suspense>

              </Carousel>
            </client-only>
          </div>
        </div>
    </template>
    
    
    <script setup>

    import { ref } from "vue";
    const { apiUrl } = useRuntimeConfig();
    import { Carousel, Slide, Pagination, Navigation } from "vue3-carousel";
    import "vue3-carousel/dist/carousel.css";
    
    const [{ data: FavDests }, { data: preferredTours }] = await Promise.all([
      useFetch(`${apiUrl}/dests/getpopulardests?country=${userCountry}`, 
       { key: "cQsyfYspDP2zM1xMe0YY9Gfv4CgQByAd" }
      ),
      useFetch(
        `${apiUrl}/tours/getpopulartours?country=${userCountry}&usercurrency=${userCurrency}`,
        { key: "Z1rvmHPxAOLvt68WZZq2BUNsHQ8I213Y" }
      ),
    ]);

   </script>
EN

回答 1

Stack Overflow用户

发布于 2022-11-22 09:29:30

如果您需要ClientOnly,还应该为此指定一个占位符:

代码语言:javascript
复制
    <ClientOnly>
      <Suspense>
        <MyFancyComponent />
        <template #fallback>
            <LoadingScreen />
        </template>
      </Suspense>
      <template #placeholder>
        <LoadingScreen />
      </template>
    </ClientOnly>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73108825

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档