vuejs
/

Vue Slots

Last Sync: Today

On this page

9
0%
5 min read
Remaining
5 minleft

Click any section to jump — progress syncs automatically

vuejs

Vue Slots

What are Slots?

Slots allow you to pass content from a parent component into a child component, enabling flexible and reusable component layouts.

Default Slot

HTMLRead-only
1
<!-- Child -->
<div>
  <slot></slot>
</div>

<!-- Parent -->
<my-component>
  <p>Hello Slot</p>
</my-component>

Named Slots

HTMLRead-only
1
<!-- Child -->
<header><slot name="header"></slot></header>
<main><slot></slot></main>

<!-- Parent -->
<my-component>
  <template v-slot:header>
    <h1>Title</h1>
  </template>
  <p>Content</p>
</my-component>

Scoped Slots

Scoped slots allow child components to pass data to slot content.

HTMLRead-only
1
<!-- Child -->
<slot :user="user"></slot>

<!-- Parent -->
<my-component v-slot="slotProps">
  {{ slotProps.user.name }}
</my-component>

Shorthand Syntax

HTMLRead-only
1
<template #header>
  <h1>Header</h1>
</template>

Fallback Content

HTMLRead-only
1
<slot>Default Content</slot>

Best Practices

  • Use slots for flexible layouts
  • Use named slots for complex UI
  • Keep slot structure simple
  • Use scoped slots for dynamic data sharing

Common Mistakes

  • Overusing slots unnecessarily
  • Not using named slots properly
  • Confusing scoped slots syntax
  • Making components too complex

Conclusion

Slots provide a powerful way to create flexible and reusable Vue components by allowing dynamic content insertion.

Try it yourself

<my-component>
  <p>Hello Slot</p>
</my-component>

Test Your Knowledge

Q1
of 3

Slots used for?

A
API
B
Content distribution
C
Database
D
Routing
Q2
of 3

Named slot syntax?

A
v-bind
B
v-slot
C
v-if
D
v-for
Q3
of 3

Scoped slots allow?

A
Loop
B
Binding
C
Data passing
D
Event

Frequently Asked Questions

What are slots?

They allow passing content into components.

What is named slot?

A slot with a specific name for structured content.

What is scoped slot?

It allows passing data from child to slot content.

Previous

vue events

Next

vue dynamic components

Related Content

Need help?

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