Skip to content

Reactive object nested in the reactive object. Any issues expected? #11636

Discussion options

You must be logged in to vote

What you found is not related to the specific example you provided. When you watch a reactive object with watch(parent.child, ...) and then mutate parent.child.b, there will not be "old" state, because you mutated the child object. for "old" state to exist, a copy of child would have to be created prior to the mutatation.

You can get something like that withwatch() => ({ ...parent.child}), ...). now Vue observes this getter function, and this getter function will create a shallow copy of the object whenever the watch is triggered. Now you will have a new and old object (but plain ones, none will be the original instance of child).

watch() => ({ ...parent.child}), (newChildCopy, oldChildCopy)

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@WhereJuly
Comment options

@LinusBorg
Comment options

@WhereJuly
Comment options

@LinusBorg
Comment options

@WhereJuly
Comment options

Answer selected by WhereJuly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants