前端学习(2585):前端怎么在响应头和请求头里面拿数据?
生活随笔
收集整理的這篇文章主要介紹了
前端学习(2585):前端怎么在响应头和请求头里面拿数据?
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
axios.interceptors.response.use( response => { //axios攔截器if (response.status === 200) { //響應(yīng)成功后if(response.headers['Authorization']){ //獲取響應(yīng)頭里面的數(shù)據(jù),**Authorization根據(jù)你響應(yīng)頭里面的數(shù)據(jù)獲取,并不是唯一值**downLoad(response.data,response.headers['Authorization'].split(';')[1].split('=')[1]);}return Promise.resolve(response);} else {return Promise.reject(response);}}, error => { //報(bào)錯(cuò)后的處理,這里不是重點(diǎn),// 服務(wù)器狀態(tài)碼不是200的情況if (error.response.status) {switch (error.response.status) {case 401:Notification.error({title: '錯(cuò)誤',message: '登錄過(guò)期,請(qǐng)重新登錄'});// 清除tokenlocalStorage.removeItem('token');store.commit('loginSuccess', null);setTimeout(() => {router.replace({path: '/login',query: {redirect: router.currentRoute.fullPath}});}, 1000);break;case 404:Notification.error({title: '錯(cuò)誤',message: '網(wǎng)絡(luò)請(qǐng)求不存在',});break;case 504:Notification.error({title: '錯(cuò)誤',message: '服務(wù)器內(nèi)部異常',});break;// 其他錯(cuò)誤,直接拋出錯(cuò)誤default:Notification.error({title: '錯(cuò)誤',message: error.response.data.message});
}return Promise.reject(error.response);}
});
?
總結(jié)
以上是生活随笔為你收集整理的前端学习(2585):前端怎么在响应头和请求头里面拿数据?的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 前端学习(2501):动态绑定样式
- 下一篇: 前端学习(2779):项目功能介绍