【问题标题】:Using async await to get data loading使用异步等待获取数据加载
【发布时间】:2021-07-07 06:44:06
【问题描述】:

我尝试使用 async-await 在 typescript vue 3 上获取数据,但是当数据未定义时(或在函数调用工作之前),此函数已经控制台

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')
    }
}

【问题讨论】:

  • 您用typescript 标记了您的问题,类型会帮助我们帮助您。 this.controller.exportOrderData是什么类型的?

标签: typescript asynchronous async-await vuejs3


【解决方案1】:

假设exportOrderData 是一个异步函数,你忘记了() 来实际调用你的函数。

let data = await this.controller.exportOrderData()

【讨论】:

  • 谢谢@Alex,这是我的错误:)
猜你喜欢
  • 1970-01-01
  • 2022-07-06
  • 2020-10-03
  • 2019-10-02
  • 1970-01-01
  • 1970-01-01
  • 2020-09-02
  • 2019-07-29
  • 1970-01-01
相关资源
最近更新 更多