从Promise.loper.los.和Axios呼叫的Promiseresult对象中获取数据

发布于 2025-02-06 05:32:01 字数 563 浏览 3 评论 0原文

我正在使用以下代码,我的目的是从返回承诺的ProsiserSult对象的数据部分中获取数据。我使用以下代码:

const promiseComment = axios.post(`${BASE_URL}/api/addComment/`, data, getDefaultHeaders());

let allPromises = []

allPromises.push(promiseComment)

Promise.all([allPromises])
    .then(function (values) {
        console.log(values[0][0]);
    });

当我安装值时,我会得到以下响应,我需要的是我在以下图像中标记的响应中的数据部分。

预先感谢

I am using the following code and my aim is to get the data from the data section of the PromiseResult object of the returned Promise. I am using the following code:

const promiseComment = axios.post(`${BASE_URL}/api/addComment/`, data, getDefaultHeaders());

let allPromises = []

allPromises.push(promiseComment)

Promise.all([allPromises])
    .then(function (values) {
        console.log(values[0][0]);
    });

When I console the values, I get the following response, what I need is the data section from the response which I marked in the following image.

enter image description here

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不一样的天空 2025-02-13 05:32:01

您需要解决内部的承诺

const promiseComment = axios.post(`${BASE_URL}/api/addComment/`, data, getDefaultHeaders());

let allPromises = []

allPromises.push(promiseComment)

Promise.all([allPromises])
    .then(values=>values).then(obj=>console.log(object.data));

you need to resolve the promise inside

const promiseComment = axios.post(`${BASE_URL}/api/addComment/`, data, getDefaultHeaders());

let allPromises = []

allPromises.push(promiseComment)

Promise.all([allPromises])
    .then(values=>values).then(obj=>console.log(object.data));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文