Lazy loading means loading a component only when it is needed, not when the app starts. This helps the app start faster and saves data.
Click to reveal answer
beginner
How do you define a lazy loaded component in Vue 3 using defineAsyncComponent?
You use defineAsyncComponent(() => import('./MyComponent.vue')) to tell Vue to load the component only when it is needed.
Click to reveal answer
intermediate
Why is lazy loading components helpful in large Vue applications?
It reduces the initial load time by splitting the app into smaller parts. Users download only what they need at first, making the app feel faster.
Click to reveal answer
beginner
What is the difference between eager loading and lazy loading components?
Eager loading loads all components when the app starts. Lazy loading loads components only when they are needed, saving time and resources.
Click to reveal answer
intermediate
Show a simple example of lazy loading a Vue component in the template.
In script setup: <code>const MyComponent = defineAsyncComponent(() => import('./MyComponent.vue'))</code>. In template: <code><MyComponent /></code>. Vue loads it only when used.
Click to reveal answer
What does lazy loading a Vue component do?
ALoads the component only when it is needed
BLoads all components at app start
CPreloads components in the background
DRemoves components from the app
✗ Incorrect
Lazy loading means loading components only when they are needed, not all at once.
Which Vue function helps create a lazy loaded component?
AuseLazyLoad
BcreateComponent
CdefineAsyncComponent
DloadComponent
✗ Incorrect
defineAsyncComponent is the official Vue function to define lazy loaded components.
Why is lazy loading good for user experience?
AIt makes the app start faster by loading less at first
BIt makes the app use more memory
CIt delays all component loading until user clicks a button
DIt disables components until needed
✗ Incorrect
Lazy loading reduces initial load time, so the app feels faster to users.
The import call is not wrapped in a function, causing immediate loading. -> Option A
Quick Check:
Wrap import in function for lazy loading [OK]
Hint: Always wrap import in a function for defineAsyncComponent [OK]
Common Mistakes:
Passing import() directly without function
Thinking import path must be absolute
Believing async components must be global
5. You want to lazy load two components, CompA and CompB, but only show CompB after CompA finishes loading and rendering. Which approach correctly achieves this?
hard
A. Import both components normally without lazy loading and use v-if to show CompB after CompA.
B. Use two Suspense components, render CompA inside first Suspense, then conditionally render CompB after CompA loads.
C. Load both components with defineAsyncComponent and render them together inside one Suspense.
D. Lazy load CompB inside CompA component's setup function.
Solution
Step 1: Understand sequential lazy loading need
We want CompB to appear only after CompA fully loads and renders.
Step 2: Use Suspense and conditional rendering
Wrap CompA in Suspense to handle loading, then show CompB conditionally after CompA is ready.
Final Answer:
Use two Suspense components, render CompA inside first Suspense, then conditionally render CompB after CompA loads. -> Option B