-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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-model.sync to automatically emit a prop's changes as an event #8403
Comments
The child component's input tag may have its own v-mode binding, and according to your idea the .sync modifier seems to emit only input events. |
I'm just hoping to suggest a clean way to extend the v-model connection up to the parent, without having to manually write an emitter. Apologies if my example implementation isn't perfect. In my idea, the v-model.sync variable be set as a prop, which got passed down from the parent. So there couldn't be a local v-model binding for that name. |
Although the feature is interesting, it is still convenience over a thing that is already made for convenience. There is also a major flaw: this would mean that a v-model could modify the component it is used on by creating a watcher or something similar. Which is currently not possible To me it looks like you want an easy way to setup a prop that is meant to be used with v model or sync. I recommend you to give a look at computed setters |
Related: vuejs/rfcs#11 does the same but just for events, not for two-way binding. Note: the name of the modifier Explanation:
i.e. it catches the event and updates the state, just like regular v-model, which does
What you're looking for is
|
I commented there as to why this cannot be solved with a directive. |
What problem does this feature solve?
v-model is a helpful tool, but it doesn't work in nested components. Instead we are supposed to use v-model on a parent component, then manually bind props and manually emit a change event within the child component. This is too verbose.
Instead, I am proposing an option for v-model that automatically emits the change event.
What does the proposed API look like?
Template for the parent component:
Template for the child component:
AS AN ALTERNATIVE TO:
Template for the parent component:
Template for the child component:
The text was updated successfully, but these errors were encountered: