$set for modifying objects in array for reactivity
See original GitHub issueVue.js version
2.1.0
Problem:
I can’t update an object in my array of objects editedPlayers[]
when I use this.$set()
. When I try to do this.editedPlayers.$set(id, this.editedPlayers[id].stats[type] + 1)
. I know this is wrong.
editedPlayers[{stats:{goals: 12, assists:3, played: 10}}, {stats:{goals: 23, assists:7, played: 30}}]
I want to update the stats.goals
in editedPlayers[someId]. Since $set or splice() can be used to substitute the current index value with another, I want just to modify it (ie: stats.goals
). What do I do?
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Vue change object in array and trigger reactivity - Stack Overflow
Here's an example that has one array of objects initialized in our app's data, and another array of objects manually set (with Vue.set())...
Read more >Update Array and Object in Vuejs. Array Change Detection
Array Change Detection. When you modify an Array by directly setting an index (e.g. arr[0] = val ) or modifying its length property....
Read more >Reactivity in Depth - Vue.js
When you directly set an item with the index, e.g. vm.items[indexOfItem] = newValue; When you modify the length of the array, e.g. vm.items.length...
Read more >Reactivity / Updating arrays and objects • Svelte Tutorial
Svelte's reactivity is triggered by assignments. Methods that mutate arrays or objects will not trigger updates by themselves. In this example, clicking the...
Read more >Reactivity for Fields, Objects, and Arrays
If a field is assigned an object or an array, the framework observes some changes to the internals of the object or array,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
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
Evan Almighty! So I wasn’t insane after all! It’s just that I wasn’t sure what problem I was running into. Thank you @simplesmiler and @yyx990803! You guys have good day 😃
Yes. Vue was unable to detect the addition of a new property
someID
to the objectthis.editedPlayers
due to the limitations of JavaScript.