我有一个文件调用 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/