question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[feature-request] Add scope prop to <slot>

See original GitHub issue

Something I’ve always wanted working with Vue components was an ability to pass some child/component data to a <slot> (while still compiling in parent scope), like the way v-for works. I’ve seen a few issues others have had with this use case, with some weird workarounds (see below).

Looking through the source code it seems like this is definitely achievable with a small modification to the slot elementDirective by some sort of scope param, to be merged with the parent somewhere around here.

As an example, here’s a jsfiddle with a (hacked-in) <scoped-slot> elementDirective which is used to build a sortable table component with a custom column template.

https://jsfiddle.net/joshglendenning/7r86jmu3/3/

It would be fairly straightforward to integrate this sort of :scope="..." behavior in the native <slot>, but I wanted to greenlight it on here before doing a pull request.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
isobitcommented, Jul 31, 2016

Also here is a gist of my scopedSlot solution if anyone is interested.

https://gist.github.com/joshglendenning/1efb58edb0598e37da348236b15c3022

0reactions
isobitcommented, Dec 15, 2016

Oh man, this is amazing, I didn’t know they were added to Vue 2. Great work as always with Vue!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Use Scoped Component Slots in Vue.js - DigitalOcean
To create scoped component <slot> , you will first need to pass properties into a named or unnamed slot from your child component....
Read more >
An introduction to Slots and Scoped Slots | Geoblink Tech blog
To create the scope we just need to add a prop in the slot tag with the data needed in the parent <slot...
Read more >
How to pass a method in Vue.js slot scope - Stack Overflow
Attributes bound to a element are called slot props. Now, in the parent scope, we can use v-slot with a value to define...
Read more >
Docs • Svelte
Readonly props can be accessed as properties on the element, tied to the component using bind:this syntax. You can use reserved words as...
Read more >
multiple props in slot-scope or v-slot with vue.js causes ...
WEB-43893 Vue: add inspection for unused slot scope parameters. I'm using Vue.js with a component framework called "Ant Design Vue", which is a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found