100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > axios请求拦截器错误_axios拦截器获取不到接口返回的response?

axios请求拦截器错误_axios拦截器获取不到接口返回的response?

时间:2023-08-22 14:59:24

相关推荐

axios请求拦截器错误_axios拦截器获取不到接口返回的response?

我的源码 我创建一个 axios 实例instance

// respone拦截器

instance.interceptors.response.use(

response => {

return response

},

error => { // 默认除了2XX之外的都是错误的,就会走这里

if (error.response) {

switch (error.response.status) {

case 401:

if (store.state.gameId) {

mit('DELETE_TOKEN')

router.replace({ // 跳转到登录页面

path: '/login?gameId=' + store.state.gameId,

query: {redirect: router.currentRoute.fullPath, gameId: store.state.gameId} // 将跳转的路由path作为参数,登录成功后跳转到该路由

})

} else {

mit('USER_LOGOUT')

}

}

}

return Promise.reject(error.response)

}

)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。