美文网首页
axios 响应拦截器,状态码判断

axios 响应拦截器,状态码判断

作者: Light_shallow | 来源:发表于2018-07-25 11:04 被阅读0次

// axios 响应拦截器,状态码判断

axiosIns.interceptors.response.use(function (response) {

const status = response.status

if (status ===200) {

return Promise.resolve(response)

}else if (status ===403) {

let headers =  response.headers;

if ("Redirect" ==headers.redirect) {//若HEADER中含有REDIRECT说明后端想重定向,

      var win =window;

while (win !=win.top) {

win =win.top;

}

win.location.href =headers['redirect-path'];

}

}else {

return Promise.reject(response)

}

})

这个是根据后端要求,后端的header中添加了REDIRECT,我在请求头里要判断有没有这个,如果有就要跳到它返回来的相对应的地址,

其中还有一个小知识点,,,,要取对象的属性中有连接符,需要通过中括号的方法,并且 在里面要写上单引号。

相关文章

网友评论

      本文标题:axios 响应拦截器,状态码判断

      本文链接:https://www.haomeiwen.com/subject/feqpmftx.html