vue.js ui加载器微调器在Nuxt3App中未正确显示

bjp0bcyl  于 2023-03-31  发布在  Vue.js
关注(0)|答案(1)|浏览(142)

数据被正确加载,但是当它们被加载时,我没有看到一个加载器向用户演示数据正在加载。同时,当我试图在模板条件中指定v-if="!loader.value"加载器时,显示正确。有一个假设,即数据加载得如此之快,以至于模板有时间渲染数据,而加载器根本不属于条件,但这个选项消失后,我试图显式地设置在浏览器中的互联网连接的速度.此外,加载状态正确显示真/假值到控制台时,应用程序进行异步请求,但不显示加载器在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>

loader的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);
  }
}
jtw3ybtb

jtw3ybtb1#

修复问题,模板由loading.value改为loading. Thx,改为@qiqqq

相关问题