-
-
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
Feature: multiple v-model bindings #4946
Comments
Component For a complex component that manages the synchronization of more than one values, explicit prop/event pairs is the proper solution. In this particular case I don't think the saved keystrokes are worth the added complexity of additional syntax. |
If we have a <dialog :open="messageOpen" @close="messageOpen = $event.value"> It's just one prop, we'll have much more for a rather complicated component. Let's look at how component libraries are doing this right now. Element and iView usually use For some components, there might be a "major" prop which covers most of child component's logic. eg. For Regarding to Vue's current design, I'd say is not proper but the most popular UI libraries are using this paradigm. People use If only prop/event pairs are the only proper way, then why I understand why Under the premises that <dialog v-sync:open="messageOpen"> Which works as syntactic sugar for <dialog :open="messageOpen" @propchange="dialogUpdate"> methods: {
dialogUpdate(prop, value) {
if (prop === 'open') {
this.messageOpen = value
}
}
} |
@Justineo I think this is more like a compile-time de-sugaring. It's actually possible by adding custom compilation modules to Alternatively, we can bring |
I think bringing Even if we cannot bring back |
@QingWei-Li @icarusion what are your opinions on this? Do you run into this problem often? |
We have had the same problem. Actually, we have implement |
I admit using When designing Element's <dialog v-sync:visible="myVisible"> But it couldn't work because a component is not allowed to modify its own props. Then there is prop/listener pair. The disadvantage of this approach is that the user has to write an event listener to manage his data. We decided it didn't make much sense for a component library. So finally we chose Generally we didn't run into this problem quite often when developing Element, perhaps just |
The primary reason for removal of the old <test :foo.sync="bar" /> is expanded into the following at compile-time: <test :foo="bar" @update:foo="value => bar = value" /> So the parent doesn't need to define a method just to do the mutation, but the child needs to emit an event instead of just mutating the prop: this.$emit('update:foo', newValue) Since this is encapsulated inside the child implementation, consumers of the library can just use |
This looks great. Can't wait to see it back. 👍 |
Nice! |
@yyx990803 |
@binsinger 就是在组件里需要更新 |
In Angular, We can use [()] to implement to way bindings ignore bindings count. May be it will be awesome If vue offer this feature |
Vue has this feature, it's the sync modifier on v-bind |
More info about .sync |
For anyone landing here and wondering: This is available in Vue |
Sometimes it is needed to build complex fill-in forms depending on multiple objects, that could be changed inside the component and should be updated at parent component.
Example of possible use (there are many such cases in complex graph-based single page apps):
<oreder-card v-model:profile="user.profile" v-model:order="order"></order-card>
Current approach:
<oreder-card :profile="user.profile" v-on:input_profile="user.profile = arguments[0]" :order="order" v-on:input_order="order = arguments[0]"></order-card>
The text was updated successfully, but these errors were encountered: