KoderSolutionKoderSolution LogoKoderSolution Logo
HomeArticlesTutorialsToolsRun CodeForumAI Lab
🖖

Vue

Topic Hub & Articles

Vue Intro

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Get Started

10 min

Vue Directives

10 min

Vue Events

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Forms

10 min

Vue Components

10 min

Vue Props

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Methods

10 min

Vue Computed Properties

10 min

Vue Watchers

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Class and Style Bindings

10 min

Vue Conditional Rendering

10 min

Vue List Rendering

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Template Syntax

10 min

Vue Teleport

10 min

Vue Suspense

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Transitions

10 min

Vue Mixins

10 min

Vue Custom Directives

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Plugins

10 min

Vue Slots

10 min

Vue Provide / Inject

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Dynamic Components

10 min

Vue Async Components

10 min

Composition API Intro

10 min

Recap Quiz

Gated

Milestone Assessment

ref vs reactive

10 min

Lifecycle Hooks

10 min

Dependency Injection

10 min

Recap Quiz

Gated

Milestone Assessment

Computed and Watch

10 min

Template Refs

10 min

Composable Functions

10 min

Script Setup

10 min

Progress
0%

0 / 32 Lessons

KoderSolutionKoderSolution LogoKoderSolution Logo

The world’s most advanced technical ecosystem for modern software engineers. Learn, build, and grow with next-generation developer tools and resources.

Facebook PageX (Twitter) ProfileYouTube ChannelContact Support

Engineering Newsletter

Subscribe for weekly software engineering tutorials, architecture guides, and developer tool updates.

Platforms

  • Technical Articles
  • Interactive Tutorials
  • AI Coding Lab
  • Developer Forum
  • Developer Tools

Pages

  • About Us
  • Contact Us
  • Privacy Policy
  • Terms of Service
  • Refund Policy
  • Disclaimer
  • Advertisement

Popular Topics

  • PHP
  • Laravel
  • Python
  • React.Js
  • MySQL
© 2026 KoderSolutionAll Rights Reserved
Developed Bymaksudur.dev
VueVue Tutorial
Lesson

Vue Slots

10 min reading
Free Course

Vue Slots: Content Distribution and Scoped Slot Architecture

Vue slots let parent components pass template markup directly into child component layouts. While props pass JavaScript data down, slots pass full HTML or other components into designated placeholders.

Slots make wrapper components like cards, modals, dialogs, and data tables deeply reusable. The child controls outer layout and spacing, while the parent controls the inner content.

flowchart TD
    Parent["Parent Template Markup"] -->|Fills Placeholder| Slot["Child slot Element"]
    Child["Child Component Data"] -->|Scoped Slot Props| Parent

Three Types of Slots in Vue 3

  • Default Slot: Catches any unnamed markup placed between <ModalCard>...</ModalCard> tags.
  • Named Slots: Targets specific layout areas like <slot name="header"> using <template #header>.
  • Scoped Slots: Lets the child pass local data up to the parent's slot template via <slot :row="item" />.

Practical SFC Slots Example

First, define ModalCard.vue with a named header slot (including fallback markup), a default slot, and a scoped footer slot.

<script setup>
defineProps({
  title: String
});
</script>

<template>
  <div class="card">
    <header class="card-header">
      <slot name="header">
        <h3>{{ title || 'Default Card Title' }}</h3>
      </slot>
    </header>

    <main class="card-body">
      <slot>Default body content appears when nothing is passed.</slot>
    </main>

    <footer class="card-footer">
      <slot name="footer" :timestamp="new Date().getFullYear()" />
    </footer>
  </div>
</template>

Next, pass custom markup from App.vue using the # shorthand for v-slot: and read the scoped timestamp property.

<script setup>
import ModalCard from './components/ModalCard.vue';
</script>

<template>
  <ModalCard>
    <template #header>
      <h2 class="accent">Confirm Account Update</h2>
    </template>

    <p>This paragraph fills the default slot area automatically.</p>

    <template #footer="{ timestamp }">
      <small>Copyright {{ timestamp }}</small>
      <button>Confirm</button>
    </template>
  </ModalCard>
</template>

Common Mistakes

  • Using #header on a Plain <div> Instead of <template>: Named slot directives like #header or v-slot:header must be placed on a <template> tag (or directly on the component tag for a single default slot).
  • Forgetting Fallback Content: Leaving <slot /> empty renders nothing if the parent omits content. Add helpful fallback markup inside <slot>Fallback</slot> when appropriate.
  • Expecting Parent Slot Content to Access Child Scope Automatically: Slot content compiles in the parent scope. To access child data inside a slot, pass it out explicitly as slot props.

Frequently Asked Questions

What is the shorthand for v-slot?

Replace v-slot: with #. For example, v-slot:header becomes #header, and v-slot:default becomes #default.

How do I check in <script setup> whether a parent passed a slot?

Call useSlots() from 'vue' inside <script setup>, or check $slots.footer inside <template> to hide empty wrapper elements conditionally.

Can I render dynamic slot names?

Yes. Write <template #[dynamicSlotName]> in the parent template, where dynamicSlotName is a reactive ref holding a string.

Save Your Progress

Unlock Your
Full Potential.

Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.

Quick Access With

Enterprise-Grade Security Protocol

Related Developer Tools & Topic Hub

Vue Topic Hub
JSON Formatter
Validate and format JSON payloads
HTML Formatter
Format HTML templates
CSS Formatter
Clean and format stylesheets
All Vue Articles
Deep-dive guides, tips & discussions
PreviousVue Plugins
Continue JourneyNext: Vue Provide / Inject

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum