Skip to content

Instantly share code, notes, and snippets.

@AndreiD
Created December 18, 2019 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndreiD/257bbcfadbbfd2cea0bed444a9ea9498 to your computer and use it in GitHub Desktop.
Save AndreiD/257bbcfadbbfd2cea0bed444a9ea9498 to your computer and use it in GitHub Desktop.
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