In Pinia, the watch
function fails to capture changes to object properties within the state
.
#2652
-
ReproductionIn Pinia, when an array is wrapped with ref and watched for changes using watch, modifications made to the array using built-in methods like push are not being detected by the watcher. Steps to reproduce the bugExpected behaviorBased on my understanding, when the value of arr is changed, the watch function can detect its changes. If the value of arr is directly modified, for example, store.arr = ['1'], this change will be detected by watch. However, if reactive is used instead of ref, the test results are the opposite: direct changes to the value of arr will not be detected, but modifications made with methods like push or unshift will be detected. Actual behaviorBased on my understanding, when the value of arr is changed, the watch function can detect its changes. If the value of arr is directly modified, for example, store.arr = ['1'], this change will be detected by watch. However, if reactive is used instead of ref, the test results are the opposite: direct changes to the value of arr will not be detected, but modifications made with methods like push or unshift will be detected. Additional informationNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
https://vuejs.org/guide/essentials/watchers.html#watch-source-types will help you understand how watch works differently with ref and reactive + the |
Beta Was this translation helpful? Give feedback.
https://vuejs.org/guide/essentials/watchers.html#watch-source-types will help you understand how watch works differently with ref and reactive + the
deep
option