question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

$set for modifying objects in array for reactivity

See original GitHub issue

Vue.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:closed
  • Created 7 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
donnyjeremiahcommented, Dec 14, 2016

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 😃

0reactions
simplesmilercommented, Dec 14, 2016

Yes. Vue was unable to detect the addition of a new property someID to the object this.editedPlayers due to the limitations of JavaScript.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found