When using the async
keyword, the function is converted into an asynchronous action and sent to the queue in the background.
This is not entirely true. The function does not run in the background or get deferred to a later time; rather, its body starts executing immediately. The main difference is that it can await
something, at which point the async function
returns a promise for its eventual result after the awaited task finishes. However, Vue does not pay attention to this returned promise (or any return value).
Therefore, code following the await
statement may appear to run out of order, after another hook like mounted
is called, but it still runs synchronously at that point. In simpler terms, if mounted
relies on data from created
, it must be done synchronously. This can still be achieved at the beginning of an async
function.
In essence, there isn't much difference between creating a promise chain in a created
method without utilizing async
.