Reputation: 1378
I have an interesting situation as follows. I have:
Basically the component tree is:
Up until now I've been able to pass down the tree using props just the web url of the result item to the scoring components and keep the score service call and data local to each score component. This nicely separates all the logic.
Nonetheless, what I'd like to achieve now is:
I've been looking at Vuex, and it seems like it may be the best approach but before I dive all the way in I'd like to verify my thoughts and if people think it'd actually work.
Should I:
set
method to ensure reactivity on new prop). And does this mean I need to pass an id of the result item and the new score then do a lookup in the result items by id to find and modify it, or can I pass through in the mutation payload the ref I have of the result item given down via props and just use that in the mutation function directly?Is this the best way to do it? Any gotchas? Thanks!
Upvotes: 1
Views: 620
Reputation: 1660
It's all as you suggested. But to add the scores to each result item you should use an array in the result item instead of using set
. In my opinion using .push
is the best way to ensure reactivity and clearity.
Comparing objects by refs works even when they are in vuex. I tested it here https://jsfiddle.net/posva/6w3ks04x/
Upvotes: 1