首页 > 解决方案 > 使用异步等待获取数据加载

问题描述

我尝试使用 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')
    }
}

标签: typescriptasynchronousasync-awaitvuejs3

解决方案


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

let data = await this.controller.exportOrderData()

推荐阅读