Skip to main content
InterviewHubPRO
Section Overview
Q11

Question 11 of 50

Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

22%
Vue.js & Composition API (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

How do Slots, Named Slots, and Scoped Slots work in Vue 3?

junior LevelCode ExampleVue & Nuxt

In Simple Words:

  • Default Slot: Injects child content (<slot />).
  • Named Slots (#name): Injects content into specific slots:
    vue
    <!-- BaseModal.vue -->
    <header><slot name="header" /></header>
    <main><slot /></main>
    
    vue
    <!-- Parent.vue -->
    <BaseModal>
      <template #header><h1>Delete Record</h1></template>
      <p>Are you sure?</p>
    </BaseModal>
    
  • Scoped Slots: Child passes data back up to the parent template:
    vue
    <!-- List.vue -->
    <slot :item="item" />
    <!-- Parent: <template #default="{ item }">{{ item.name }}</template> -->