将结果存储在Aurelia中的全局变量中

如何从printData中的getData()访问返回的数据?我可以将数据存储在全局变量中吗?

以下是我的示例:

home.js

export class Home {
    //d;
    constructor() {
        this.printData();
    }
    getData() {
        httpClient.fetch('example.com/api/v')
            .then(response => response.json())
            .then(data => {
                return data;
                //this d = data;
            });
    }
    printData() {
        var data = this.getData();
        console.log(data.name);
        //console.log(this.d.name);
    }
}
my_winter13292 回答:将结果存储在Aurelia中的全局变量中

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2708327.html

大家都在问