Skip to content

Instantly share code, notes, and snippets.

@AndreiD
Created Dec 18, 2019
Embed
What would you like to do?
mediumx
export default {
state: () => ({
loading: false
}),
mutations: {
SET_DATA(state, { id, data }) {
state[id] = data;
}
}
};
--------------------------
axios.js
export default function({ $axios, redirect, store }) {
$axios.onError(error => {
const code = parseInt(error.response && error.response.status);
if (code === 500) {
redirect("/500");
}
});
$axios.interceptors.request.use(
config => {
store.commit("SET_DATA", { data: true, id: "loading" });
return config;
},
error => {
return Promise.reject(error);
}
);
$axios.interceptors.response.use(
response => {
store.commit("SET_DATA", { data: false, id: "loading" });
return response;
},
error => {
return Promise.reject(error);
}
);
}
----------------
now you have access to $store.state.loading
here's how to use it for example, with a vuetify button
<v-btn
min-height="50"
block
class="primary"
:loading="$store.state.loading"
type="submit"
>Login</v-btn>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment