Trying a simple example:
async function asyncFun () {
var value = 10
return value
}
console.log(await asyncFun())
It always throw await is a reserved word. No matter the preset-env I change. Anyone could help on the correct settings for using async/await in this template ?
Thanks
Here is a demo repository: https://github.com/gabrielstuff/async-await-vue
Please refer to this issue https://github.com/babel/babel-eslint/issues/319.
As is explained by @hzoo,
you have to use await in an async function. The former isn't that syntax. You would be calling a function named async with a non-async arrow function.
Ok, thanks. Fixed with creating a whole async function around the await call.
It is better to read, but stills, I'm not sure if this is the right way to call:
async function asyncFun () {
var value = 10
return value
}
(async () => { console.log(await asyncFun()) })()
Looks a bit hard to read.
The code has been updated.
Yeah, await cannot be used at the top level.
console.log(await asyncFun()) -> asyncFunc().then(v = console.log(v))
Most helpful comment
Yeah,
awaitcannot be used at the top level.console.log(await asyncFun())->asyncFunc().then(v = console.log(v))