Skip to content

Add Documentation for passing slots to child components #2390

Open
@LuWa-at-work

Description

@LuWa-at-work

Hey i found this solution for passing slots to child components of a component. I think this should be in the official docu, because it's a cool trick and has a few usecases 😊

Code to pass on the $slots:

<template v-for="(index, name) in $slots" v-slot:[name]>
  <slot :name="name" />
</template>

Code to pass on the $scopedSlots require some more configuration, but it is similar to passing the $slots:

<template v-for="(index, name) in $scopedSlots" v-slot:[name]="data">
  <slot :name="name" v-bind="data"></slot>
</template>

By defining the templates like this in our parent component we passing on all the slots defined at the place where we use the parent component.

source:

https://devinduct.com/blogpost/59/vue-tricks-passing-slots-to-child-components

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions