Skip to content

Allow value-less prop assignments #6589

Closed
@loilo

Description

@loilo

What problem does this feature solve?

I'm not too sure how common this is, but here's my use case:

I'm using Vue pretty frequently to create wrapper components of all kinds. When doing so, it happens regularly that several individual props need to be passed down to child components.

As an example, a RangeSlider component accepts the props min, max, step, disabled and value and passes them to an underlying <input>. The template might look like this:

<input
    type="range"
    :value.sync="value"
    :min="min"
    :max="max"
    :step="step"
    :disabled="disabled">

This adds quite a lot of visual noise.

What does the proposed API look like?

I'd like to propose the possibility to omit the value from prop assignments. An assigned prop p without a value will use the component's p property as its value.

This will be much clearer by example:

Basic example

Suggested:

<input :min :max>

equals current:

<input :min="min" :max="max">

Modifiers are ignored

Suggested:

<input :value.sync>

equals current:

<input :value.sync="value">

With that, the introducing example could be reduced to this:

<input type="range" :value.sync :min :max :step :disabled>

I'd consider that a much more elegant and concise, however possibly a little less obvious, syntax.

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions