0

I have been trying to add loading spinner to my NuxtJS project using the loading configuration: https://nuxtjs.org/api/configuration-loading.

However, the documentation is hard to understand, I have no idea how to apply it to my project. Did any have any ideas of how to add loading spinner using that?

Thanks in advance,

2 Answers 2

2

So you can create a custom loading:

We can create our custom component in components/loading.vue:

<template lang="html">
  <div class="loading-page" v-if="loading">
    <p>Loading...</p>
  </div>
</template>

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

<style scoped>
.loading-page {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.8);
  text-align: center;
  padding-top: 200px;
  font-size: 30px;
  font-family: sans-serif;
}
</style>

Then, we update our nuxt.config.js to tell Nuxt.js to use our component:

export default {
  loading: '~/components/loading.vue'
}

And then in your compenent you can show and hide with the:

this.$nuxt.$loading.start() to start the loading bar and this.$nuxt.$loading.finish() to finish it.

You can put this in the callbacks of a request.

Sign up to request clarification or add additional context in comments.

3 Comments

I've attempted same as your suggestion, but nothing shows up when I call this.$nuxt.$loading.start(). I'm not sure whether something is missing.
In my case - I dont know how to disable this behaivor. The custom loader visible when route changes, but I have no declared start() & stop() events in code.
Unfortunately, it doesn’t work. I can change the nuxt loading with a simple HTML file but it doesn’t work with Vue components.
1

probably it's about z-index value

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.