使用async await进行数据加载

6

我尝试使用async-await在TypeScript Vue 3中获取数据,但是当数据为undefined(或在函数调用之前工作)时,该函数已经被控制台输出

private async exportDataOrder() {
    await this.getDataExport()                          // function call
    let data = await this.controller.exportOrderData    // result function
    if (data) {
      console.log(data, 'dari vue')
      console.log('waiting')
    }
}

2
你在问题中标记了 typescript,类型会帮助我们更好地帮助你。this.controller.exportOrderData 的类型是什么? - Denis Frezzato
1个回答

3
假设 exportOrderData 是一个异步函数,你忘记了使用 () 来实际调用该函数。
let data = await this.controller.exportOrderData()

谢谢@Alex,那是我的错误 :) - edwin dhwmn

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接