4

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.

2
  • 2
    Check out my answer here ( stackoverflow.com/a/44737095/7814783) . There is even an example fiddle Commented Jul 6, 2017 at 11:14
  • you should start with what you tried and how you are currently loading your data. post an example Commented Jul 6, 2017 at 11:48

1 Answer 1

4

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>
Sign up to request clarification or add additional context in comments.

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.