-
In the sample code below, data changes in the store do not cause data changes in the Component,Is this a bug or am I using the wrong method? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
I Thinks this is because Just Try to use reactive like these Just visit my github & see how iimplement this one. https://github.com/amancoder28/petite-vue-counter |
Beta Was this translation helpful? Give feedback.
-
Yes, when you pass in a primitive value as a prop, it will indeed not be reactive. You are supposed to be passing the initial state of a component, not a reactive one. Note however that if you changed the This behavior is not a bug but one way to work around it is to pass reactive props as lambda functions for which you can set up getters inside the child component (example: https://codepen.io/fry98/pen/JjrEGbB). Be aware that this is pretty much always unnecessary though because both the parent's state and your Edit: In the |
Beta Was this translation helpful? Give feedback.
Yes, when you pass in a primitive value as a prop, it will indeed not be reactive. You are supposed to be passing the initial state of a component, not a reactive one. Note however that if you changed the
counter
property to be an object, it would actually remain reactive in the child component (code: https://codepen.io/fry98/pen/ExwZPyQ).This behavior is not a bug but one way to work around it is to pass reactive props as lambda functions for which you can set up getters inside the child component (example: https://codepen.io/fry98/pen/JjrEGbB).
Be aware that this is pretty much always unnecessary though because both the parent's state and your
reactive()
store are accessible from withi…