1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > axios请求失败 response.data返回的状态码及错误信息获取

axios请求失败 response.data返回的状态码及错误信息获取

时间:2023-09-18 23:52:41

相关推荐

axios请求失败 response.data返回的状态码及错误信息获取

axios请求失败,后端接口返回的状态码及错误信息获取

使用封装的elementUI后台框架,后台框架自定义封装并返回的code码转态(全部的返回数据,如下所示):

浏览器查看:返回的 error 信息

{"message":"User wither username 13600000001 existed,"status":400,"timestamp":"-05-21T16:11:19:381"}

(返回error数据)调用代码示下:

1.Get请求:

// axios.get(serverPath+'/login')

···略···.bind(this).catch(error => {if (error.response.status == 400) {console.log(“此处多次点击登录按钮 ∈ 重复登录”);console.log(“用户名或密码不正确”);console.log(error.response.message);} else {console.log(“登陆失败”);}});

2.Post请求:

// axios.post(serverPath+'/login')

···略···.bind(this).catch(error => {if (error.response.data.status == 400) {console.log(“此处多次点击登录按钮 ∈ 重复登录”);console.log(“用户名或密码不正确”);console.log(error.response.data.message);} else {console.log(“登陆失败”);}});

注意:

请求方式不同(get/post),获得的error数据的调用方式也不同,具体代码参考上文。(不一定非要和我的保持一样。)

相关博客:

axios请求失败,后端接口返回的状态码及错误信息获取(博主自留, 具体参考某某项目登录页login.vue代码:重复登录逻辑。)

以上就是关于 “ axios请求失败,后端接口返回的状态码及错误信息获取 ” 的全部内容。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。