ankurk91 / vue-loading-overlay

Vue.js component for full screen loading indicator :cyclone:
https://ankurk91.github.io/vue-loading-overlay/
MIT License
1.24k stars 101 forks source link

Automatize Ajax requests #27

Closed taianrj closed 5 years ago

taianrj commented 5 years ago

Hello, Ankur!

It's not a issue, just a question. Could you help me?

Is there an easy way to show your component everytime an ajax request is started and hide it everytime an ajax request is completed?

ankurk91 commented 5 years ago

If you are using library like axios, then yes. You can use axios intercepters. BTW jQuery ajax do similar feature to intercept ajax calls.

taianrj commented 5 years ago

Thank you for the fast answer. I'm trying to use jquery ajax interception to achieve it and I'm doing it to start and it's working, but it's creating many instances of the component (one overlaping the other).

Note: It's hapenning because I'm doing more than one ajax request at the same time.

How to avoid it?

$(function () { $.ajaxSetup({ beforeSend: function () { loader = self.$loading.show(); } }); });

ankurk91 commented 5 years ago

You have to store instance in a variable, then hide the loader if instance exists, make a new instance, store it in same variable.

This a simple programming issue.

taianrj commented 5 years ago

Thank you! Your component is amazing!