我正在调用一个 Rest API,该 API 返回至少 2 个成功状态代码。
正常的 200 OK 和 202 Accepted 状态代码。
两者都返回正文中的内容。
如果我在邮递员中执行我的电话,我可能会得到类似的东西
Status code: 202 Accepted. With Body "Queued" or some other values
or
Status code: 200 OK. With Body "ValueOfSomeToken"
Making the call with axios in my nuxt app:
this.$axios.$get('/Controller/?id=1')
.then((response)=>{
if(response=='Queued'){
//Do something
}
else if (response=='Expired'){
//Do something
}
else{
//Do something
}
})
.catch((error)=>{
console.log(error);
});
..有效,但我实际上想获取状态代码(因为 202 对于正文响应还有其他值)
我不知道如何读取状态代码。
我尝试使用 (response,code) =>... 但代码什么也不是。
您可以使用非$
- 前缀函数,例如this.$axios.get()
代替this.$axios.$get()
得到完整的答复
// Normal usage with axios
let { data } = await $axios.get('...'));
// Fetch Style
let data = await $axios.$get('...');
(source https://axios.nuxtjs.org/helpers#fetch-style-requests)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)