Sync Modifier support object properties
See original GitHub issueWhat problem does this feature solve?
Sync Modifier support object properties. For example, I have a myObj object, it has a foo and a bar property.
myObj: {
foo: 'foo',
bar: 'bar'
}
This feature could use update:myObj.foo
and update:myObj.bar
to update the value.
this.$emit('update:myObj.foo', 'new-foo');
this.$emit('update:myObj.bar', 'new-bar');
What does the proposed API look like?
Currently, I need to use below format
<MyComponent :foo.sync="myObj.foo" :bar.sync="myObj.bar"></MyComponent>
props: ['foo', 'bar']
...
this.$emit('update:foo', 'new-foo');
this.$emit('update:bar', 'new-bar');
But with this new feature:
<MyComponent :myObj.sync="myObj"></MyComponent>
props: ['myObj']
...
this.$emit('update:myObj.foo', 'new-foo');
this.$emit('update:myObj.bar', 'new-bar');
It becomes more simple and clear, especially when the object has many properties.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:10
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Vue's new and improved prop.sync. In Vue 2.3, the ... - Medium
sync modifier, which was removed in the past, has been reintroduced in a new way. This post is going to explore two approaches...
Read more >Issue with passing objects via sync? - Get Help - Vue Forum
I am new to vue js. I got stuck with a problem with vue js. Here is the fiddle. https://jsfiddle.net/tmwbkL40/ <div class="apple"> <inputt ......
Read more >Vue.js Emit props & Sync modifier - Francium Tech
External JavaScript sync modifier comes with even more flexibility for updating multiple props in objects. Checkout the docs here. Note of caution: There...
Read more >Confusion with Object-Props and Sync Modifier : r/vuejs - Reddit
With .sync, the child component has no ability to control the modifications. It's all controlled by the parent. The child just sends an...
Read more >Vue JS Tutorial - Props, Events, Sync Modifier [ Component ...
Let's look at transmitting data between parent and child components using Props, Custom Events and the . sync Modifier (links below).
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Although I can see the point of this proposal, I don’t feel that it’s particularly needed. In some way it encourages passing multiple values in an object to avoid having to specify multiple props. It is very easy to abuse object props by tucking more and more properties into it, making it some sort of “super prop”. However, I think having an explicit list of props makes your component’s interface easier to understand.
using
sync
with an object work well.myObj
take more than two key. inner childwho is more harder to understand? who is better? why?