javascript - axios錯(cuò)誤處理的對(duì)象error.response 是空
問題描述
_this.$http.post(`/company/${id}/out`, { access_token: _this.access_token,}).then((res) => { let info = res;}).catch((err) => { console.log(err.response); // err.response 是 undefined})},
我想在 403 或者 401 的時(shí)候去處理這個(gè)錯(cuò)誤,但是拿不到這個(gè)狀態(tài)碼。但是官網(wǎng)上就是這么用的。
axios.get(’/user/12345’) .catch(function (error) { if (error.response) { // The request was made and the server responded with a status code // that falls out of the range of 2xx console.log(error.response.data); console.log(error.response.status); console.log(error.response.headers); } else if (error.request) { // The request was made but no response was received // `error.request` is an instance of XMLHttpRequest in the browser and an instance of // http.ClientRequest in node.js console.log(error.request); } else { // Something happened in setting up the request that triggered an Error console.log(’Error’, error.message); } console.log(error.config); });
我的axios 的版本是 ^0.16.1。
問題解答
回答1:403不清楚,但是我記得之前我查的答案是401會(huì)被瀏覽器攔截處理掉,js拿不到
相關(guān)文章:
1. javascript - js 有什么優(yōu)雅的辦法實(shí)現(xiàn)在同時(shí)打開的兩個(gè)標(biāo)簽頁間相互通信?2. java - 新手做一個(gè)安卓視頻播放器,想實(shí)現(xiàn)一個(gè)進(jìn)度條,按鈕那種在視頻下方懸浮的功能,不知道思路!3. android - 目前有哪些用Vue.js開發(fā)移動(dòng)App的方案?4. html5和Flash對(duì)抗是什么情況?5. 想找個(gè)php大神仿個(gè)網(wǎng)站。6. javascript - 一個(gè)抽獎(jiǎng)的效果(如圖)?7. javascript - 怎樣限制同一個(gè)瀏覽器不能登錄兩個(gè)賬號(hào)8. css3 - Typecho 后臺(tái)部分表單按鈕在 Chrome 下出現(xiàn)靈異動(dòng)畫問題,求解決9. java - android代碼重構(gòu):如何把a(bǔ)pp設(shè)置里的頭像UI做成通用的?10. javascript - jquery怎么給select option一個(gè)點(diǎn)擊時(shí)觸發(fā)的事件,如圖 如果選擇自定義觸發(fā)一個(gè)時(shí)間?
