Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

axios按照你封装,然后then()里面不执行 #10

Open
YTU94 opened this issue Jul 10, 2017 · 5 comments
Open

axios按照你封装,然后then()里面不执行 #10

YTU94 opened this issue Jul 10, 2017 · 5 comments

Comments

@YTU94
Copy link

YTU94 commented Jul 10, 2017

我想问下为什么,是不是因为使用promise的原因,求help

@YTU94 YTU94 changed the title axios安装你封装,然后then()里面不执行 axios按照你封装,然后then()里面不执行 Jul 10, 2017
@hzzly
Copy link
Owner

hzzly commented Jul 10, 2017

你catch一下,看是不是请求出错了

@YTU94
Copy link
Author

YTU94 commented Jul 11, 2017

解决了,我看了下是你在配置axios时,判断放回状态成功时用的是reject导致后续不执行,我换成resolve就可以(我理解的)。

@dtdths
Copy link

dtdths commented Aug 8, 2017

@YTU94
//返回状态判断(添加响应拦截器) axios.interceptors.response.use((res) => { //对响应数据做些事 if (!res.data.success) { return Promise.reject(res); } return res; }, (error) => { // _.toast("网络异常", 'fail'); return Promise.reject(error); });
其中如果 res.data.success 不存在,走reject,可能是这有问题。比如我们后端一直返回res.data.status='ok'啥的,么有success

@YTU94
Copy link
Author

YTU94 commented Aug 8, 2017

了解了,谢谢

@TonyDalian
Copy link

每个服务器返回的成功标志不一样,大部分返回status=200

//返回状态判断
axios.interceptors.response.use((res) =>{
if(!res.status==200){
// _.toast(res.data.msg);
return Promise.reject(res);
}
return res;
}, (error) => {
// _.toast("网络异常", 'fail');
return Promise.reject(error);
});

把楼主的if (!res.data.success) 改为 if(!res.status==200) 我本地测试OK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants