-
Notifications
You must be signed in to change notification settings - Fork 668
SetProps on object prop child changes does not trigger computed or watcher #761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The above "working" example doesn't actually work because other properties on the object are unset by calling setProps with the partial object. So, it seems like I should be passing in the full object to setProps still but it isn't forcing an update on computed/watchers. It does seem the reactivity does happen if I copy the the initial object with Object.assign or the spread operator and then change the copied object. |
Yes the problem is you're calling setProps with the same object. When setProps reassigns the same object, the property getter returns early because the object reference hasn't changed. I'll look into a way to fix this |
The solution has been to throw an error if you're doing this. Instead, you'll need to create a new object when you call setProps |
The above comment says you will need to ' create a new when you call setProps'. A new what. It looks like a word is missing. |
@CindyConway a new object |
Version
1.0.0-beta.20
Reproduction link
https://github.com/drewtownchi/VueRouterTranspile
Steps to reproduce
Create some data to be passed down as a prop...
Create a component that accepts an object prop.
Initialize the test with propsData and verify the child key sub1 is set correctly via the computed property to "hello".
Change the sub1 data in the test to "test2" and update the props using setProps
Check that the sub1 is set correctly via computed property or data (if using a watcher, both don't work)
What is expected?
the computed property would be updated to the new data passed down via props
What is actually happening?
The computed property is giving the old data.
Expected: "test2"
Received: "hello"
This is working correctly in the browser. The data outputted to the screen reflects the change in sub1 when sub1 is changed in the parent.
Edit: This was working before in previous versions. So maybe I am just doing it the wrong way now? Now should I be just passing in the updated key?
This seems to work. Not sure if I should no longer be passing in an updated object?
The text was updated successfully, but these errors were encountered: