javascript / beginner
Snippet
Async Components
Async components are only loaded from the server when they are actually needed, which helps reduce the initial loading time of your application.
snippet.js
1
2
3
4
5
import { defineAsyncComponent } from 'vue';const AsyncButton = defineAsyncComponent(() =>import('./components/MyButton.vue'));
vue
Breakdown
1
defineAsyncComponent(() => ...)
Tells Vue to define a component that will be loaded lazily.
2
import('./components/MyButton.vue')
Uses a dynamic import to fetch the component file only when it is requested.