小编nuk*_*o12的帖子

Axios - 设置拦截器以在错误时重试原始请求

我需要为所有 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)

javascript vue.js axios vuex

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

axios ×1

javascript ×1

vue.js ×1

vuex ×1