vuejs
/

Vue Suspense

Last Sync: Today

On this page

10
0%
5 min read
Remaining
5 minleft

Click any section to jump — progress syncs automatically

vuejs

Vue Suspense

What is Suspense?

Suspense is a built-in Vue component used to handle asynchronous components and display fallback content while loading.

Why Use Suspense?

  • Handle async components easily
  • Show loading states
  • Improve user experience
  • Simplify async UI logic

Basic Syntax

HTMLRead-only
1
<Suspense>
  <template #default>
    <AsyncComponent />
  </template>
  <template #fallback>
    <p>Loading...</p>
  </template>
</Suspense>

Async Component Example

JavaScriptRead-only
1
const AsyncComponent = defineAsyncComponent(() =>
  import('./MyComponent.vue')
);

Fallback Content

Fallback content is displayed while async components are being loaded.

Multiple Async Components

Suspense waits for all async dependencies inside it to resolve before rendering.

When to Use

  • Lazy-loaded components
  • API-based rendering
  • Complex async UI flows
  • Loading screens and placeholders

Best Practices

  • Use clear fallback UI
  • Keep async logic simple
  • Combine with lazy loading
  • Avoid overusing suspense blocks

Common Mistakes

  • Not providing fallback content
  • Overusing suspense unnecessarily
  • Complex nested suspense usage
  • Ignoring loading states UX

Conclusion

Vue Suspense simplifies handling async components and enhances user experience by managing loading states effectively.

Try it yourself

<Suspense>
  <template #fallback>
    <p>Loading...</p>
  </template>
</Suspense>

Test Your Knowledge

Q1
of 3

Suspense used for?

A
Routing
B
Async handling
C
Styling
D
State
Q2
of 3

Fallback means?

A
Error
B
Loading UI
C
API
D
Event
Q3
of 3

Works with?

A
Sync
B
Async components
C
CSS
D
HTML

Frequently Asked Questions

What is Suspense?

It handles async components with fallback UI.

What is fallback?

Content shown while loading.

When to use Suspense?

For async components and loading states.

Previous

vue teleport

Next

vue performance

Related Content

Need help?

Explore our comprehensive docs or start a chat with our tech experts.