-
Notifications
You must be signed in to change notification settings - Fork 545
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
v-bind property value shorthand #83
Comments
The API change presented in this PR and One of those times, @yyx990803 argued that At first sight, I feel like this change trades faster writing with slower comprehension (not a good deal), as it departs from HTML's familiar P.S. Are you aware about the |
As I mentioned, I think this is a really nice improvement if added. I find myself writing
But that would of course not use the value defined in Also I understand it could make the code a bit weird to read for people unaware of the feature, but so does other Vue features like CSS
Take this Vuetify playground as an example, most of the data properties are repeated.
Could be way shorter with the proposed change. Also it looks more like ES6 objects which accepts a similar syntax as @GavinRay97 mentioned. Also, @leopiccionia how do people still remember this Robson stuff? lmao it happened five years ago. |
I would make the argument that when dealing with component attributes with a colon I think we can come to a consensus that Vue templates are not HTML, nor are they JS. They are an independent entity with slightly different semantics. And that's okay. Those unique semantics are why we love Vue. This sort of binding mirrors the way I would expect JS object expressions to behave. The syntax is identical to ES6 property value shorthands, which, in my experience, nearly everyone uses. In the context of "Bound Vue attribute = JS expression", I think there is little ambiguity as to mechanics or intent here.
I did find that during researching whether this proposal/RFC has been presented before. I understand that functionally, the result is the same, but the appeal and attraction of Vue to most I believe has always been about it's ergonomics and semantics. We write Vue because it is beautiful and comprehensible, and to me, the object values |
@phiter That playground could use this to tighten up the syntax, but I think in that case the verbosity is on purpose.
|
@amoliski this syntax is worse. Vue style guide recommends using one prop per line if you're going to pass three or more props. I think this is a bit harder to read than what we're used to. Of course, we could use this instead: <v-text-field
v-model="model"
v-bind="{
label,
hint,
placeholder,
shaped,
outlined,
rounded,
solo,
filled,
clearable,
loading,
flat,
dense,
'single-line':singleLine,
'persistent-hint': persistentHint,
counter: counterEn ? counter : false,
}"
/> This would make more sense, but now you have commas and can be weird at first sight. |
Fair enough, I went a bit overboard collapsing it down to take up less space in the comment. |
Seems reasonable.. to toss another slight deviation into the ring, I prefer something like this currently.. reads well, highlights well, digests easily imo <v-text-field
v-model="model"
v-bind="{
label,
hint,
placeholder,
shaped,
outlined,
rounded,
solo,
filled,
clearable,
loading,
flat,
dense
}"
:single-line="singleLine"
:persistent-hint="persistentHint"
:counter="counterEn ? counter : false"
>
</v-text-field> There's another RFC floating around about adding property negation ( |
What would |
@CyberAP that should either be invalid or resolve to the data referenced by |
This looks good to me, nothing wrong with some commas. It's not an extra character since the colons are saved |
I'd love to see this shorthand become a reality. So many of our properties are :src="src", width="width" etc.. |
Would love to have this terse syntax |
This would be appreciated. |
I would also love this. It is a little funny when you dig into this topic and find that this idea comes up multiple times each year and everyone seems to have the same syntax-intuition. That to me sounds like this syntax can be intuitively understood, since a similar syntax is used by js property shorthand. I get a question about a shorthand for props nearly every time I teach vue to a new developer. @yyx990803 stated his opinion on the topic in the year 2016. Given the many many request I hope he reconsiders. Vue is losing some of its popularity lately and I think that such a little Quality of Life Improvement could go a long way. |
Since there was no RFC-Discussion open; I created an RFC regarding this issue. I proposed a solution which effectively supports this syntax: <v-text-field
v-model="model"
{label}
{hint}
{placeholder}
{shaped} /> |
This has been added to Vue 3.4 via this PR vuejs/core#9451 |
Wow, holy smokes. Was not expecting that, half a decade later! 😁 |
I have a working rough proof-of-concept here:
GavinRay97/vue@524d4c4
Allow binding property keys to values of the same name, the way that ES6 shorthand for object syntax works.
Inspired by this Twitter comment:
The text was updated successfully, but these errors were encountered: