Suggestion: Allow multiple names for a named slot
See original GitHub issueWhat problem does this feature solve?
Flexibility in using slots. So you could allow a slot to take multiple variations of a name. For example:
<slot names="['name-one', 'name-two', 'name-three']"/>Then, you can pass any one of those names into the slot and it will render. I have a workaround I use currently by adding the following code into the created()
method:
['nameTwo', 'nameThree'].forEach((slotName) => {
if ({}.hasOwnProperty.call(this.$slots, slotName)) {
this.$slots.nameOne = this.$slots[slotName];
delete this.$slots[slotName];
}
});
But it would be great if this could be done automatically.
What does the proposed API look like?
I current use this code in created()
:
['nameTwo', 'nameThree'].forEach((slotName) => {
if ({}.hasOwnProperty.call(this.$slots, slotName)) {
this.$slots.nameOne = this.$slots[slotName];
delete this.$slots[slotName];
}
});
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Using Vue Named Slots to Create Multiple Template Slots
To give our slot a name, <slot> elements have a special name attribute, that let us differentiate between multiple slots.
Read more >Tips to Supercharge Your Slots (Named, Scoped, and Dynamic)
With named slots we can create multiple slots in a component, and then access them by their unique names. Here we create a...
Read more >Shadow DOM slots, composition
Slots allow to show elements from light DOM in specified places of shadow DOM. There are two kinds of slots: Named slots: <slot...
Read more >Composing Custom Elements With Slots And Named Slots
Thanks to named slots, you can easily create a complex custom elements that compose multiple pieces together. For example, a nav bar that...
Read more >A Guide to Vue Slots - LearnVue
To give our slot a name, <slot> elements have a special name attribute, that let us differentiate between multiple slots.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
IMHO it is essential to keep a consistent vocabulary across the whole team, especially for larger apps. Let collaborators refer to the same slot with different names doesn’t seem to be a good practice and I think we won’t accept this. Thanks.
This should work: