Skip to content

How do we use the scope slot? #1375

Open
@PoliWen

Description

@PoliWen

Info

How do we use the scoped slot?

difficulty: easy
title:How do we access the state of the child component when we use the slot?
tags: Slots

Question

In some cases, we need to get the child component's data from the parent component through the slot,
How do we use the scope slot?

Template

MyComponent .vue

<div>
  <slot :text="greetingMessage" :count="1"></slot>
</div>

App.vue

<MyComponent v-slot="slotProps">
  {{ slotProps.text }} {{ slotProps.count }}
</MyComponent>

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions