Skip to content

New prop shorthand #5835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
maurop123 opened this issue Jun 6, 2017 · 4 comments
Closed

New prop shorthand #5835

maurop123 opened this issue Jun 6, 2017 · 4 comments

Comments

@maurop123
Copy link

What problem does this feature solve?

When passing props to a component, the following pattern is very common,

<my-component :propA="propA" :propB="propB" />

I am proposing that when the prop name is the same as the variable name being passed to it, that the following more concise syntax be applicable,

<my-component :propA :propB :propC />

This would mimic ES6's object property declaring shorthands (like here http://www.benmvp.com/learning-es6-enhanced-object-literals/)

What does the proposed API look like?

<my-component :propA :propB :propC />

instead of

<my-component :propA="propA" :propB="propB" />

@sirlancelot
Copy link

sirlancelot commented Jun 7, 2017

If you're using ES6 already (via webpack's vue-loader), you can try <my-component v-bind="{ propA, propB, propC }">

@sqal
Copy link
Contributor

sqal commented Jun 7, 2017

#2877

@LinusBorg
Copy link
Member

LinusBorg commented Jun 7, 2017

Quoting Evan from #2877:

Took me some time to respond this because I am not really a fan of this proposal but it wasn't immediately clear to me what turned me off. I tried it out and it just felt weird to me:

<comp :a :b></comp>

Now I realize it's because of the semantic implication of HTML attributes that have no values - they are usually boolean attributes. An attribute with no value indicates the "presence of an attribute" or "truthiness". Implicitly expanding to a binding overloads this perception.

In addition - if a prop in the child component is declared with type Boolean, the presence of the attribute indicates a true value. This would cause prop and :prop to have very different meanings, and is technically a breaking change.

@maurop123 Do you have any arguments against the issues Evan raised? If not, I would close this feature request as a duplicate.

Also, @sirlancelot mentioned a nice "workaround" to make something like this possible with the current API.

@maurop123
Copy link
Author

Thank @sirlancelot for the approach. I just tried it and it works great.

@LinusBorg I do agree with Evan's argument. Thank you for bringing it up.

I'll close it now 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants