i am creating an application in VueJS and i would like to create a service or global variable which stores if the client is making a request to the server. I have been thinking in configure an interruptor which sets the global variable to true when is making a request, and when the request is finished sets the variable to false.
So when i use a loader component it shows only when the variable is true.
Example:
// As i do
<form @submit.prevent="save">
<h2>{{ $t('organization.labels.organization')}}</h2>
<div class="row">
<div class="col m6 s12" v-if="$route.name == 'organization'">
<form-input-text :title="$t('organization.labels.client_number')" :model.sync="form.client.client_number" ></form-input-text>
</div>
<div class="col m6 s12">
<div class="center" v-if="loader.is_loading">
<material-loader></material-loader>
<br> <small>{{ $t('organization.labels.loading')}}</small>
</div>
</div>
</div>
</form>
// As it should work
<form @submit.prevent="save">
<h2>{{ $t('organization.labels.organization')}}</h2>
<div class="row">
<div class="col m6 s12" v-if="$route.name == 'organization'">
<form-input-text :title="$t('organization.labels.client_number')" :model.sync="form.client.client_number" ></form-input-text>
</div>
<div class="col m6 s12">
<div class="center" v-if="$loader.is_loading"> <== $loader
<material-loader></material-loader>
<br> <small>{{ $t('organization.labels.loading')}}</small>
</div>
</div>
</div>
</form>
Any idea?? The main idea is to have to create a variable is_loading, for each view to know if the user is requesting for something.