我不明白为什么我创建的async/await函数没有等待。
async mustWait() {
this.response = await this.service.mustBePrintedFirst();
console.log('I will wait');
}
mustBePrintedFirst() {
http.get(.....);
console.log('I must be printed first');
}发布于 2019-02-18 01:46:42
像下面这样返回一个承诺。
mustBePrintedFirst() {
return new Promise(resolve => {
resolve('whatever you want to resolve');
console.log('I must be printed first');
});
}在你的情况下,它将是
mustBePrintedFirst() {
http.get(...).toPromise() // something ike this
}https://stackoverflow.com/questions/54735744
复制相似问题