我需要为所有 axios 调用设置一个全局拦截器。我在 vuex 操作中定义它们,如果有 429 状态代码,则需要调用一个操作,然后在执行该操作后,重试原始请求。我正在学习拦截器,但我不知道如何正确设置它,以及它是否可以在export default. 谁能帮我?
axios.interceptors.use( (response) => {
// if no status error code is returned get the response
return response
}, (error) => {
console.log(error)
// here I need to retry the ajax call after that my loadProxy action is made and a 429 status code is sent from the server
return Promise.reject(error);
})
export default new Vuex.Store({
actions: {
loadProxy({ commit }) {
// here I have an axios get request …Run Code Online (Sandbox Code Playgroud)