gpt4 book ai didi

javascript - 缺少 ) 在使用异步等待的参数列表之后

转载 作者:行者123 更新时间:2023-12-05 08:30:56 29 4
gpt4 key购买 nike

我有一个文件调用 find.js,我使用 node find.js 运行,我的节点是版本 10 我不知道为什么我无法使用 async await。

const axios = require("axios");

const execute = async () => {
let searchResult;
try {
searchResult = await axios.post(
"https://example.io/car",
{
ids: [12,31],
},
{
headers: {
"Accept-Language": "en-US",
},
}
);
} catch (error) {
console.log("error", error);
}

return searchResult;
};

console.log(await execute()); // error on this line

最佳答案

因为 async 函数 returns an implicit Promise ,你可以改变这个:

console.log(await execute());

对此:

execute().then(res => console.log(res));

否则,您需要在另一个 async 函数中调用 execute,因为 await 只能在 中使用>异步函数。

关于javascript - 缺少 ) 在使用异步等待的参数列表之后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61264054/

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