【发布时间】:2019-06-09 17:59:10
【问题描述】:
async function getOrderdata(orderId) {
//await the response of the fetch call
let response = await fetch('http://localhost:3245/api/Orders/' + orderId);
//proceed once the first promise is resolved.
let data = await response.json();
//proceed only when the second promise is resolved
return data;
}
我有显示的代码,我想在另一个 js 文件中使用 getOrderdata 函数?
【问题讨论】:
-
在另一个
async函数中使用即可:let x = await GetOrderData(...); -
const data = await getOrderdata(id) -
您可以在另一个文件中使用这个
async function,就像在另一个文件中使用普通function一样。 -
请告诉我们另一个文件的代码,您是如何尝试调用
getOrderdata,以及出了什么问题。
标签: javascript asynchronous promise async-await