Сохраните результат в глобальной переменной в Аурелии - PullRequest
1 голос
/ 27 января 2020

Как получить доступ к возвращенным данным из getData () в printData? Могу ли я сохранить данные в глобальной переменной?

Ниже приводится пример, приведенный ниже:

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);
    }
}
...