[feature-request] Add scope prop to <slot>
See original GitHub issueSomething 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).
- http://forum.vuejs.org/topic/366/slot-as-an-item-row-template
- http://forum.vuejs.org/topic/526/repeating-table-row-with-slot
- https://forum.vuejs.org/topic/3456/slots-but-with-data-binding/2
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:
- Created 7 years ago
- Comments:14 (7 by maintainers)
Top GitHub Comments
Also here is a gist of my
scopedSlot
solution if anyone is interested.https://gist.github.com/joshglendenning/1efb58edb0598e37da348236b15c3022
Oh man, this is amazing, I didn’t know they were added to Vue 2. Great work as always with Vue!