-
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
Replace v-bind's .sync with a v-model argument #8
Replace v-bind's .sync with a v-model argument #8
Conversation
I'm just an end user of Vue so my options probably aren't quite as valid as others, but here's my 2 cents. I didn't know As for spread support, I've never used it in v-bind to begin with. To me it makes the code much less readable. I've always used multiple v-binds (shorthand :). I would have no problem not supporting spread on Though I have to wonder when multiple two-way bindings would be used on a single component? Any control I can think of only has a single "value" to two-way bind to. And a larger form component would two-way bind to a object, with child components for each control getting their own two-way binder. |
Vuetify's autocomplete component uses |
Because I personally have never used |
In a project at work, I currently have a dynamic component that's passed an object using When it comes to duplicating the object spread behavior, I'm a fan of option 1. I think that the consistency is valuable, and it would make v-model's underlying behavior more clear (at the cost of it being a little more verbose). |
I agree. The two way thinking is more in line with v-model. I got confused by the examples though.
Thinking further, couldn't a new syntax be possible for syncing between two different props or set of props between the child and parent? i.e.
If there are a number of props to sync, use objects.
Of course, just like in v-bind, the child must have the properly defined props available. You mentioned the current compiler not balking when the child and parent component props don't have the same name. I don't think that should be a requirement, i.e. that both prop names match. For instance, in the docs there is this example:
The new suggested v-model equivalent of this would be (as I understand it):
Or it could be:
Or!!! When you have just Or am I in left field, as is so often the case? 😁 Scott |
I like the how option 1. for spread is consistent with |
@pansyromek I was already thinking about |
@zaun haha :D, I was joking at first but when I wrote it down, I realized I kinda like that syntax :D |
|
||
## Summary | ||
|
||
Deprecating `v-bind`'s `.sync` modifier and replacing it with an argument on `v-model`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to deprecate or remove it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove. 🙂 Just fixed!
Yes, I was just highlighting that this behavior would remain the same and how it's different from the proposed behavior of
If I'm understanding you correctly, isn't that what the proposal already does?
I'm not sure this syntax makes sense. What are you thinking it would compile to? And what would the shape of each object be?
As you mentioned, the current proposal is not suggesting it be a requirement. 🙂
Yes, I think so. 😉 @panstromek @zaun I agree with @Justineo that with Despite the consistency of option 1, I'd estimate that |
Hmm... so is this correct, if I change <input v-model="xxx">
<!-- would be shorthand for: -->
<input
:value="xxx"
@update:value="newValue => { xxx = newValue }"
> Your use of If that's true, the rest all makes sense. Or, I'm definitely in left field. 😁
I don't know. That is a step more than my knowledge can help with.
They'd have to be equal to work, I think. Ok. Contemplating more on that, that is a problem. Nevermind. What I was thinking of accomplishing was to avoid having to write multiple Scott |
I love this proposal and agree completely that this is a more straightforward API. I would like to echo what @panstromek said about considering a shorthand to really cement this. (I know it's a separate RFC, just leaving the comment here.) Since |
@smolinari No, because
That's what these proposals are for.
@sirberus As long as we don't go for option 1, we're not making the most common use case more verbose, so there's no need for a shorthand. |
I agree with @ChrisFritz. Even though I like the |
But the need for a two-way bind is not always the use case. There are some cases where a |
There's no such proposal in this RFC. |
Maybe it is worth to decouple models from props (just like data is decoupled from props)? This would result in:
The advantage of this would be, that you dont need to configure model definitions in two places inside the options. Also it would be possible to "automatically convert unused models to data": |
@backbone87 I'm not sure I fully understand what you're suggesting, but I think it may be more related to this RFC, which you may be interested in. |
I am voting for option 1, as it feels very natural and consistent:
It could automatically fall back to the old behaviour if the prop is not an object:
And I like that idea of using |
@chrisvfritz export default {
props: ['a', 'b'],
models: ['c', 'd'],
data: () => ({ e: 1, f: 2 }),
} where models functions like a mix of data+props. |
This RFC is now in final comments stage. An RFC in final comments stage means that:
|
Rendered