(This particular inquiry pertains to TypeScript, not JavaScript. Despite a resolved JavaScript query below, this issue remains specific to TypeScript).
I am attempting to implement async functionality in Vue 3.0 using TypeScript.
The following code operates effectively without async:
// file: components/HelloWorld.vue
<template>
<div class="hello">
<h1>{{ msg }}</h1>
</div>
</template>
<script lang="ts">
import {defineComponent} from 'vue'
export default defineComponent({
name: 'HelloWorld',
props: {
msg: String,
},
async setup() { // <-- works fine without 'async'
const test = 'test'
// await doSomethingAsynchronous()
return {
test,
}
},
})
</script>
Upon implementing async setup()
, the element "HelloWorld" vanishes from the page, accompanied by an error message within the Firefox console:
"Uncaught (in promise) TypeError: node is null (runtime-dom.esm-bundler.js)"
Transitioning async setup()
to setup()
allows the code to function properly, albeit inhibiting async/await usage within the setup function.
Therefore, my inquiry revolves around utilizing async/await within the setup() function while employing TypeScript.
UPDATE:
A response regarding the question posed at why i got blank when use async setup() in Vue3 demonstrates that async setup()
functions adequately with JavaScript, suggesting it should similarly work seamlessly with TypeScript as well.