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');
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');
md5-3748bded9409f9aea18e0fa67a2f7a89
```javascript
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.
You can use v-bind without directive arguments:
<MyComponent v-bind="myObj"></MyComponent>
...
props: ['foo', 'bar']
...
@javoski it seems more clear than before. So I can use like below code, right?
this.$emit('update:foo', 'new-foo');
this.$emit('update:bar', 'new-bar');
but why not just myObj.foo? Especially the object has many properties.
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.
You can use
v-bindwithout directive arguments:<MyComponent v-bind="myObj"></MyComponent> ... props: ['foo', 'bar'] ...
using sync with an object work well.
<child :my-obj.sync = "myObj"/>
myObj take more than two key.
inner child
this.$emit("update:myObj",newObj)
who is more harder to understand? who is better? why?
You can use
v-bindwithout directive arguments:<MyComponent v-bind="myObj"></MyComponent> ... props: ['foo', 'bar'] ...using
syncwith an object work well.<child :my-obj.sync = "myObj"/>
myObjtake more than two key.
inner childthis.$emit("update:myObj",newObj)who is more harder to understand? who is better? why?
THis is great! works like a charm!
Most helpful comment
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.