ui loader spinner 在 Nuxt 3 App 中没有正确显示

问题描述 投票:0回答:1

数据加载正确,但是加载时,我没有看到加载程序向用户展示数据正在加载。同时,当我尝试在模板条件中指定时,显示为

v-if="!loader.value"
loader 正确显示。假设数据加载速度如此之快以至于模板有时间渲染数据,并且加载器根本不符合条件,但是在我尝试在浏览器。此外,当应用发出异步请求时,加载状态正确地向控制台显示 true/false 值,但不在 UI 中显示加载程序。这里有什么解决方案?

Nuxt .vue 组件:

    <template>
      <div v-if="loading.value" class="loader">
        <div class="lds-ellipsis">
          <div />
          <div />
          <div />
          <div />
        </div>
      </div>
      <v-container fluid fill-height v-else>
        <v-layout justify-center align-center>
          <div class="education">
            <div class="education__timeline">
              <v-timeline>
                <v-timeline-item
                    content appears here after successful loading
                </v-timeline-item>
              </v-timeline>
            </div>
          </div>
        </v-layout>
      </v-container>
    </template>

<script setup lang="ts">
    const eduTimeline = ref<IEduTimeline[]>([]);
    const loading = ref(true);
    onMounted(() => {
      nextTick(async () => {
        try {
          console.log(loading.value) // correctly loggs out - true
          const {data} = await useFetch<IData>('/data.json')
          if (data && data.value && data.value.education) {
              eduTimeline.value = data.value.education;
          }
        } catch (error) {
          console.error(error);
        } finally {
          loading.value = false
          console.log(loading.value) // correctly loggs out - false
    
        }
      })
    });

<script>

加载程序的CSS:

.loader {
  display: flex;
  justify-content: center;
  margin-top: 6em;
}
.lds-ellipsis {
  display: inline-block;
  position: relative;
  width: 80px;
  height: 80px;
}
.lds-ellipsis div {
  position: absolute;
  top: 33px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #4177be;
  animation-timing-function: cubic-bezier(0, 1, 1, 0);
}
.lds-ellipsis div:nth-child(1) {
  left: 8px;
  animation: lds-ellipsis1 0.6s infinite;
}
.lds-ellipsis div:nth-child(2) {
  left: 8px;
  animation: lds-ellipsis2 0.6s infinite;
}
.lds-ellipsis div:nth-child(3) {
  left: 32px;
  animation: lds-ellipsis2 0.6s infinite;
}
.lds-ellipsis div:nth-child(4) {
  left: 56px;
  animation: lds-ellipsis3 0.6s infinite;
}
@keyframes lds-ellipsis1 {
  0% {
    transform: scale(0);
  }
  100% {
    transform: scale(1);
  }
}
@keyframes lds-ellipsis3 {
  0% {
    transform: scale(1);
  }
  100% {
    transform: scale(0);
  }
}
@keyframes lds-ellipsis2 {
  0% {
    transform: translate(0, 0);
  }
  100% {
    transform: translate(24px, 0);
  }
}
vue.js nuxt.js vuetify.js server-side-rendering vuetifyjs3
1个回答
0
投票

修复了问题,模板从

loading.value
更改为
loading
。谢谢,@qiqqq

© www.soinside.com 2019 - 2024. All rights reserved.