Member-only story

Understanding Async Components in Vue3

Shawn Kang
6 min readFeb 22, 2024

--

Async Components in Vue3

Vue series of articles

Background

When developing Vue projects, most people will use components. In the parent component, the child components are generally loaded in sequence, where the parent component is loaded after the child component. For example:

// app.vue
<script setup>
import {onMounted} from 'vue'
import ChildVue from './child.vue'
onMounted(() => {
console.log('app')
})
</script>
<template>
<ChildVue />
</template>
// child.vue
<script setup>
import {onMounted} from 'vue'
onMounted(() => {
console.log('child')
})
</script>

Running result:

child
app

If a page has many child components, since the child components are loaded first, the parent component may experience a rather long white screen waiting time. How can we make the child.vue component load asynchronously? Vue3 provides a new defineAsyncComponent method to implement asynchronous components.

Usage

  • Lazy Loading: Asynchronous components allow delaying the loading of…

--

--

Shawn Kang
Shawn Kang

Written by Shawn Kang

Focusing on front-end development and internet writing. Sharing technical tutorials and original fiction. https://skstory.online/

No responses yet

Write a response