- axios错误处理的对象error.response是空
-
聚码交流
-
0
2

- yhuxAvNbtxUM
0000-00-00 00:00:00
- 回帖
_this.$http.post(`/company/${id}/out`,{access_token:_this.access_token,}).then((res)=>{letinfo=res;}).catch((err)=>{console.log(err.response);//err.response是undefined})},我想在403或者401的时候去处理这个错误,但是拿不到这个状态码。但是官网上就是这么用的。axios.get('/user/12345').catch(function(error){if(error.response){//Therequestwasmadeandtheserverrespondedwithastatuscode//thatfallsoutoftherangeof2xxconsole.log(error.response.data);console.log(error.response.status);console.log(error.response.headers);}elseif(error.request){//Therequestwasmadebutnoresponsewasreceived//`error.request`isaninstanceofXMLHttpRequestinthebrowserandaninstanceof//http.ClientRequestinnode.jsconsole.log(error.request);}else{//SomethinghappenedinsettinguptherequestthattriggeredanErrorconsole.log('Error',error.message);}console.log(error.config);});我的axios的版本是^0.16.1。