【发布时间】:2019-02-08 22:06:21
【问题描述】:
我正在调用另一个类中的一个函数,其中包含一个 API 请求。我想将 API 请求的响应返回给我调用函数的类。但是 Console.log 会写出“Promise {pending}”。
let test: Object = Utility.getManager(this.props.graphClient);
console.log(test);
这里我用一个参数调用类“Utility”中的函数“getManager”。
public static async getManager(Client: MSGraphClient): Promise<Object> {
return await Client
.api("/me/manager")
.version("v1.0")
.get(async (error, response: any, rawResponse?: any): Promise<any> => {
// handle the response
console.log(response);
return await response;
});
}
在这里,我尝试将 API 请求的响应发送回以保存在“测试”中。
【问题讨论】:
标签: reactjs typescript sharepoint spfx