gpt4 book ai didi

axios - Nuxt Axios 模块读取状态码

转载 作者:行者123 更新时间:2023-12-04 14:32:13 29 4
gpt4 key购买 nike

我正在调用一个返回至少 2 个成功状态代码的 Rest API。
正常的 200 OK 和 202 Accepted 状态代码。
两者都在正文中返回一个内容。
如果我在 postman 中执行我的电话,我可能会得到类似的信息

状态代码:202 已接受。使用正文“排队”或其他一些值
enter image description here
enter image description here
或者

状态代码:200 OK。带有正文“ValueOfSomeToken”
enter image description here
在我的 nuxt 应用程序中使用 axios 进行调用:

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 )

关于axios - Nuxt Axios 模块读取状态码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50101903/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com