Open guda-art opened 1 week ago
Please provide a minimal reproduction.
Please provide a minimal reproduction.
deep: true will output trigger but false not
This behavior is expected. According to the docs: https://vuejs.org/api/reactivity-core.html#watch
When using a getter source, the watcher only fires if the getter's return value has changed. If you want the callback to fire even on deep mutations, you need to explicitly force the watcher into deep mode with { deep: true }. Note in deep mode, the new value and the old will be the same object if the callback was triggered by a deep mutation:
In your case, { deep: true }
causes the watcher to trigger when any property of the object changes, not just number
.
This behavior is expected. According to the docs: https://vuejs.org/api/reactivity-core.html#watch
When using a getter source, the watcher only fires if the getter's return value has changed. If you want the callback to fire even on deep mutations, you need to explicitly force the watcher into deep mode with { deep: true }. Note in deep mode, the new value and the old will be the same object if the callback was triggered by a deep mutation:
In your case,
{ deep: true }
causes the watcher to trigger when any property of the object changes, not justnumber
.
Firstly, my initial question was about whether to enable deep or not, and the behavior should be consistent (even if the value of other attributes changes when deep is enabled, it will not trigger the observer for that attribute). The link explains another issue, that is, when deep is enabled, if the attribute source that the getter depends on is replaced, even if the return value remains unchanged, the observer will still be triggered
Vue version
3.5.6
Link to minimal reproduction
no
Steps to reproduce
1.case1
2.case2
when use deep: true; number no change but other prop of obj change trigger still (Verified not to trigger when other change)
What is expected?
Consistent behavior
What is actually happening?
no Consistent behavior
System Info
Any additional comments?
No response