【发布时间】:2020-07-29 05:16:41
【问题描述】:
我正在学习从节点/打字稿应用程序进行 http 调用。我有以下方法,使用npm package Axios 对假的api 端点进行http get 调用。
public GetTrailById(trailId: number) : string {
console.log("Entered the method.");
const res = axios.get("https://reqres.in/api/users?page=2")
.then((res: { data: any; }) => {
console.log("inside then");
return "this is good, got response";
})
.catch((err: { response: any; }) => {
console.log("inside catch");
return "this is not good, inner catch";
});
console.log("nothing worked");
return "nothing worked";
}
当我运行上述代码时,我确实看到了以下控制台输出,但没有来自 then 块或 catch 块的控制台输出。我不明白控件的去向。
我看到的输出:
Entered the method.
nothing worked
我期望看到的:
Entered the method.
inside then //or inside catch
有人可以帮我弄清楚我在这里做错了什么吗?
【问题讨论】:
标签: node.js typescript http axios