axios - 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?
解决方案
感谢其他地方的另一位贡献者,这就是答案:
当您执行 console.log 时,您将 JSON 对象添加到 Axios 响应的字符串中,因此 JSON 对象被转换为字符串,因此对象对象。
如果您将其作为两条单独的线进行,例如
console.log('Axios Response');
console.log(response.data);
然后它将作为实际对象输出。
虽然它是一个 HTTP 请求,而不是将其输出到控制台,我要做的是打开浏览器开发工具的网络选项卡,然后选择 XHR 选项卡,然后请求将出现在那里,您可以检查那里有完整的响应正文,而无需记录它。
推荐阅读
- javascript - Angular Http 错误未与 Micronaut HttpResponse.serverError() 映射
- python - 在 Z3 或 Z3py 中部分描述函数
- python - 语法错误 discord.py
- jquery - 在第二个滑动指示器之后下一个滑动指示器未激活
- google-cloud-platform - cloudbuild.yaml 和 cloudmigrate.yaml 在 Google Cloud 中有什么区别?
- python - 得到结果时的不同概率
- java - 如何将关联值添加到已经有键的映射中?
- ios - 关闭应用程序后如何保持用户登录?
- php - php中的include,require和use函数有什么区别?
- c# - 循环遍历不同的 ListBox