标签:for console cookie cep promise win request 过期 lse
1.对于携带cookie,token的信息进行判断
2.参数为接受到后台的返回数据,类似code状态值,判断后对于cookie或token进行统一处理
axios.interceptors.request.use((config) => { if (Cookies.get(‘BJCSI_USER_LOGINKEY‘)) { const id = Cookies.get(‘BJCSI_USER_ID‘) - 0 const loginKey = Cookies.get(‘BJCSI_USER_LOGINKEY‘) config.headers = { ‘Content-Type‘: ‘application/x-www-form-urlencoded‘, ‘id‘: id, ‘loginKey‘: loginKey } } return config }, (err) => { return Promise.reject(err) }) axios.interceptors.response.use(res => { const code = res.data.code if (code === 11) { console.log(‘登录过期重新登录‘) Cookies.remove(‘BJCSI_USER_LOGINKEY‘) Cookies.remove(‘BJCSI_USER_ID‘) window.location = ‘/‘ } else { return res } }, err => { let errResponse = err.response const errMsg = {‘msg‘: code(errResponse.status)} if (err && errResponse) { return Promise.reject(errMsg) } })
标签:for console cookie cep promise win request 过期 lse
原文地址:https://www.cnblogs.com/hurenjie/p/10516896.html