Vue Academy · Lesson

Scoped Slots: Passing Data to Parent

slot :data='value', v-slot='{ data }' on the parent side, render prop pattern.

Lesson 2 of 413 steps

Scoped Slots: Passing Data to Parent is a free Vue Academy lesson on CoddyKit. This is lesson 2 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the Vue Academy learning path, and your progress syncs across the web and the CoddyKit app. The Vue Academy course includes 4 lessons in total.

The Limitation of Plain Slots

Plain slots let a parent pass markup down, but the parent cannot access the child internal data. Scoped slots solve this by letting the child expose data back up to the slot content.

Binding Data on a Slot

The child binds attributes on its <slot> element, called slot props. These are passed to whatever the parent renders.

<!-- List.vue -->
<ul>
  <li v-for="(item, i) in items" :key="item.id">
    <slot :item="item" :index="i"></slot>
  </li>
</ul>

Receiving Slot Props

In the parent, the value of v-slot becomes an object containing all the slot props the child bound.

<List :items="users">
  <template v-slot:default="slotProps">
    {{ slotProps.index }}: {{ slotProps.item.name }}
  </template>
</List>

Destructuring Slot Props

Because the slot value is just an object, you can destructure it inline for cleaner code.

<List :items="users">
  <template v-slot:default="{ item, index }">
    {{ index }}: {{ item.name }}
  </template>
</List>

Shorthand for Default Scoped Slot

When you only use the default slot, you can put v-slot directly on the component tag instead of a nested template.

<List :items="users" v-slot="{ item }">
  {{ item.name }}
</List>

Renaming and Defaults

Destructuring supports renaming and default values, just like normal JavaScript.

<template v-slot:default="{ item: user, index = 0 }">
  {{ index }} - {{ user.name }}
</template>

Named Scoped Slots

Named slots can be scoped too. Combine the name with the destructured props.

<DataTable :rows="rows">
  <template #cell="{ value, column }">
    <strong>{{ column }}: {{ value }}</strong>
  </template>
</DataTable>

Renderless Components

Scoped slots enable the renderless component pattern: a component handles logic and state but renders no markup of its own - it just exposes data through a scoped slot and lets the parent decide the UI.

A Renderless Mouse Tracker

The component tracks the cursor and exposes coordinates. It renders only its default slot, passing x and y.

<!-- Mouse.vue setup -->
<slot :x="x" :y="y"></slot>

Consuming the Renderless Component

The parent supplies all visuals and reads the exposed data, fully decoupling logic from presentation.

<Mouse v-slot="{ x, y }">
  <p>Cursor is at {{ x }}, {{ y }}</p>
</Mouse>

Scoped Slots vs Composables

Composables often replace renderless components in Vue 3 for pure logic reuse. But scoped slots still win when the child must control iteration or structure (like a list or table) while the parent customizes each item.

Quick Check

How does a parent receive data exposed by a scoped slot?

Recap

You learned scoped slots let a child expose data upward by binding props on its <slot>. The parent reads them through the v-slot value (often destructured), enabling renderless components that separate logic from presentation.

Free to start

Learn HTML with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
42
Lessons
156

Frequently Asked Questions

Is the “Scoped Slots: Passing Data to Parent” lesson free?

Yes — any 3 lessons of the Vue Academy learning path, including “Scoped Slots: Passing Data to Parent”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The Vue Academy course includes 4 lessons in total.

What will I learn in “Scoped Slots: Passing Data to Parent”?

slot :data='value', v-slot='{ data }' on the parent side, render prop pattern. You practise Vue Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Vue Academy?

No prior experience is required. Vue Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 2 of 4.

How long does the “Scoped Slots: Passing Data to Parent” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Vue Academy lesson?

Yes. Every Vue Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Named Slots and Default Slot
  2. Scoped Slots: Passing Data to Parent
  3. Dynamic Slot Names
  4. Slot Fallback Content and Checking Slots
← Back to Vue Academy