首页 > 解决方案 > Axios's response, what's in it??.....const response = await axios

问题描述

I'm using Axios in WP e.g.

const response = await axios.delete(universityData.siteURL + "/wp-json/wp/v2/note/" + thisNote.getAttribute("data-noteID"))

All works fine but what I don't understand is the structure / content of 'response'. How do I interrogate 'response'? I had assumed for instance if I did console.log('Axios response: ' + response.data) I'd get a nicely laid out JSON like OO output in the Chrome console panel. But all I see is: Axios response: [object Object]

I can do this response.data.userNoteCount and I get something sensible back. BTW 'userNoteCount' is a field I added to my JSON for my custom post type. But how else do I see all the content of response without specifically having to target it?

标签: axios

解决方案


感谢其他地方的另一位贡献者,这就是答案:

当您执行 console.log 时,您将 JSON 对象添加到 Axios 响应的字符串中,因此 JSON 对象被转换为字符串,因此对象对象。

如果您将其作为两条单独的线进行,例如

console.log('Axios Response'); console.log(response.data);

然后它将作为实际对象输出。

虽然它是一个 HTTP 请求,而不是将其输出到控制台,我要做的是打开浏览器开发工具的网络选项卡,然后选择 XHR 选项卡,然后请求将出现在那里,您可以检查那里有完整的响应正文,而无需记录它。


推荐阅读