I try use async-await to get data on typescript vue 3, but this function already console when the data is undefined (or before function call working)
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')
}
}
A better and cleaner way of handling the promise is through the async/await keywords. You start by specifying the caller function as async and then use await to handle the promise. Because of the await keyword, the asynchronous function pauses until the promise is resolved.
forEach is synchronous, while fetch is asynchronous. While each element of the results array will be visited in order, forEach will return without the completion of fetch, thus leaving you empty-handed.
C# Language Async-Await Async/await will only improve performance if it allows the machine to do additional work.
The async and await keywords enable asynchronous, promise-based behavior to be written in a cleaner style, avoiding the need to explicitly configure promise chains. Async functions may also be defined as expressions.
Assuming that exportOrderData
is an async function, you forgot the ()
to actually call your function.
let data = await this.controller.exportOrderData()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With