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.

Suggestion: Allow multiple names for a named slot

See original GitHub issue

What 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:closed
  • Created 5 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
Justineocommented, Sep 25, 2018

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.

0reactions
znarcommented, Jan 6, 2022

This should work:

<slot :slot-props="containerProp" name="container">
    <slot></slot>
</slot>
Read more comments on GitHub >

github_iconTop 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 >

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