How to add a new property to vue (object) data?
See original GitHub issueMy data goes below
data: {
contacts: {
"1": {
isSelected: false,
UID:"1",
cardType: 0
},
"2": {
isSelected: false,
UID:"2",
cardType: 0
},
"3": {
isSelected: false,
UID:"3",
cardType: 0
},
}
...
I could use this method to add new contact, but it got a compatibility problem, so I wonder are there some other ways to add new property to object, or I’d better change to use array instead of object.
this.contacts = Object.assign({}, this.contacts, newObj);
Thanks a lot.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
How to add properties to a object in vue - Stack Overflow
Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. – jeremy.Wu.
Read more >Using Vue.js $set() method to set data object properties
We can use the $set() method in a v-on:click directive to set a property to a value when the element is clicked. This...
Read more >How do I add a new object into an existing object and retain ...
The following inserts a new object into an already existing one. Vue.set(this.cards[x].group[y] = Object.assign(this.cards[x].group[y], ...
Read more >How to dynamically create reactive properties in Vue
Vue does not allow adding new root-level properties to the data object after the initialization of a component. This is because Vue modifies ......
Read more >How to properly add props to data object in Vue.js - Medium
It turned out that I couldn't add the property directly to the data object. Instead, I should use Object.assign() . Well, a code...
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 FreeTop 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
Top GitHub Comments
Thanks, using the set method, and It’s OK now.
Read the docs: Vue.set