如何在 Nuxt.js 中删除第一个加载圆 div (id="nuxt-loading")?

Num*_*chi 3 nuxt.js

我从这里复制了一些文件:https : //codesandbox.io/s/github/nuxt/nuxt.js/tree/dev/examples/custom-loading? from- embed

  • 页面/about.vue
  • 页面/index.vue
  • 组件/loading.vue

并设置了 nuxt.config.js。见下文。

项目/组件/loading.vue

<template>
  <div v-if="loading" id="loader">
    <p>asdasdasd...</p>
  </div>
</template>

<script>
    export default {
        data: () => ({
            loading: false
        }),
        methods: {
            start () {
                this.loading = true
            },
            finish () {
                this.loading = false
            }
        }
    }
</script>
Run Code Online (Sandbox Code Playgroud)

项目/nuxt.config.js

{
    // ...
    loading: '~/components/loading',
    // ...
}
Run Code Online (Sandbox Code Playgroud)

下一步,我将 setTimeout ms 从 1000 设置为 60000 以进行测试。我在第一次加载时得到了另一个加载页面,而不是components/loading.vue。第二个和另一个加载很好,但不是第一个。

我在 F12 之后看到的,我在项目中找到了它。 项目/.nuxt/loading.html

<style>
#nuxt-loading {
  visibility: hidden;
  opacity: 0;
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  animation: nuxtLoadingIn 10s ease;
  -webkit-animation: nuxtLoadingIn 10s ease;
  animation-fill-mode: forwards;
  overflow: hidden;
}

@keyframes nuxtLoadingIn {
  0% {
    visibility: hidden;
    opacity: 0;
  }
  20% {
    visibility: visible;
    opacity: 0;
  }
  100% {
    visibility: visible;
    opacity: 1;
  }
}

@-webkit-keyframes nuxtLoadingIn {
  0% {
    visibility: hidden;
    opacity: 0;
  }
  20% {
    visibility: visible;
    opacity: 0;
  }
  100% {
    visibility: visible;
    opacity: 1;
  }
}

#nuxt-loading>div,
#nuxt-loading>div:after {
  border-radius: 50%;
  width: 5rem;
  height: 5rem;
}

#nuxt-loading>div {
  font-size: 10px;
  position: relative;
  text-indent: -9999em;
  border: .5rem solid #F5F5F5;
  border-left: .5rem solid #D3D3D3;
  -webkit-transform: translateZ(0);
  -ms-transform: translateZ(0);
  transform: translateZ(0);
  -webkit-animation: nuxtLoading 1.1s infinite linear;
  animation: nuxtLoading 1.1s infinite linear;
}

#nuxt-loading.error>div {
  border-left: .5rem solid #ff4500;
  animation-duration: 5s;
}

@-webkit-keyframes nuxtLoading {
  0% {
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}

@keyframes nuxtLoading {
  0% {
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}
</style>

<script>
window.addEventListener('error', function () {
  var e = document.getElementById('nuxt-loading');
  if (e) {
    e.className += ' error';
  }
});
</script>

<div id="nuxt-loading" aria-live="polite" role="status"><div>Loading...</div></div>

<!-- https://projects.lukehaas.me/css-loaders -->
Run Code Online (Sandbox Code Playgroud)

所以我的问题。我怎样才能禁用它?

chr*_*ett 7

您可以使用文件中的loadingIndicator选项配置 Nuxt 的默认加载屏幕nuxt.config.js

这里的文档:https : //nuxtjs.org/api/configuration-loading-indicator

例子:

// nuxt.config.js
loadingIndicator: {
  name: 'circle',
  color: '#3B8070',
  background: 'white'
}
Run Code Online (Sandbox Code Playgroud)

loadingIndicator选项也可以是指向自定义 HTML 模板的字符串(如果您不想使用 Nuxt 的内置加载器)。

// nuxt.config.js
loadingIndicator: '~/loading.html'
Run Code Online (Sandbox Code Playgroud)