Skip to content

Ability to pass scoped slots to descedants in templates #7178

Closed
@shameleo

Description

@shameleo

What problem does this feature solve?

The related issue (#5151) is closed, so I need to clarify my point.

It should exist convenient way to define template for items of hierarchical component (for example, tree or list with sections).
I know, it can be solved with render functions, but it is not so "native" way of building components in vue as in react. I mean, writing / reading render functions is more uncomfortable for average vue user, because they are used only occasionally. It's even worse, if user need to setup webpack / babel / jsx. So I think, render functions should be avoided for not-so-advanced cases.

Slots can be "passed" to children using templates, like this:

<child>
    <template slot-scope="props">
        <slot v-bind="props"></slot>
    </template>
</child>

But there are some drawbacks:

  1. This creates wrapper function on each level. First, we have wrapper. Then wrapper of wrapper, and so on.
  2. This breaks fallback content (default template) feature.

What does the proposed API look like?

<child>
    <slot slot-scope></slot>
</child>

Remark

I propose syntax, which is boiled down version of first markup, and can be supported by compiler. Here is my test implementation (it seems quite easy): shameleo/vue-slot-pass-demo@bdb6cbb
If you give me green light, I'll try to prepare PR. If something is missed in implementation, let me know, please.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions