I wonder where and how to setup a loading icon in VueJS, when the data my site depends on, isn't ready.
Do you know how to do this?
Would be nice and helpful.
I wonder where and how to setup a loading icon in VueJS, when the data my site depends on, isn't ready.
Do you know how to do this?
Would be nice and helpful.
Considering you are using axios which is currently the most used http client for vue.js you would do something like
data: function() {
return { results: [], loading: true};
}
And now let's say you load on create
created: function() {
axios.get('/path/to/my/data/endpoint')
.then(function(response) {
this.result = response.data;
this.loading = false;
}.bind(this))
.catch(function() {
this.loading = false;
}.bind(this));
}
And in your template you have something like
<img src="/path/to/my/loading/icon" v-if="loading" />
<ul v-else>
<li v-for="result in results"> ... </li>
</ul>