M
M
myskypesla2017-09-15 10:35:28
Vue.js
myskypesla, 2017-09-15 10:35:28

How to make a preloader in Vue.js?

Hello.
There is a project, when going through the routes, the preloader should turn on and until the content is loaded, the preloader should be active, then disappear. There is a Preloader.vue
component , so far I have implemented it like this, but this is just a temporary option to lay out the preloader:

<template lang="pug">
  .preloader(v-show="loading")
</template>

export default {
  data() {
    return {
      loading: true,
    };
  },
  mounted() {
    setTimeout(() => {
      this.loading = false;
    }, 2000);
  },
  watch: {
    $route() {
      this.loading = true;
      setTimeout(() => {
        this.loading = false;
      }, 2000);
    },
  },
};
</script>

Question: how to make a full-fledged one, so that until all the content on the page is loaded, do not remove it? I tried through ready() and created(), but these methods only work on the initial render.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Kulakov, 2017-09-15
@kulakoff Vue.js

You can define it in the root component template. And if vuex is used, then set the showloader state property, make it false|true depending on when you need to show or hide this loader.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question