无法从axios获取json

时间:2018-08-18 18:20:28

标签: javascript ecmascript-6 axios

JS新手。

我想从axios requet获取json响应

val myBooleanProperty: Property<Boolean> = project.objects.property(Boolean::class.javaObjectType)

但是我不明白为什么它仍在控制台中显示const activities = Axios.get("https://api.github.com/events").then(response => response.data); console.log(activities);

1 个答案:

答案 0 :(得分:-1)

原因是Axios.get()返回了诺言。您可以在Promise上应用.then()回调,以处理Promise解决的问题。

这是您可以做的:

Axios.get("https://api.github.com/events").then(response => {
    const activities = response.data;
    console.log(activities);
});


您还可以根据使用的节点版本使用较新的async/await

const foo = async () => {
    const response = await Axios.get("https://api.github.com/events");
    const activities = response.data;
    console.log(activities);
}