`old value` in parameters of `watch` callback maybe incorrect
Vue version
3.3.4
Link to minimal reproduction
Steps to reproduce
- open SFC Playground links above
- open console
- click buttons in "oldVal incorrect" area, and check console, two messages will be printed on each click, and they will be the same, which is unexpected.
https://github.com/vuejs/core/assets/51878637/c1fe1621-7586-48a1-9984-6d12441ea6f8
What is expected?
Printed second parameter oldVal
of the watch
callback should not be equal to the first parameter val
, since it's internal value has been changed when user click button.
What is actually happening?
The old value is the same as the latest value, exactly like when clicking buttons in "oldVal correct" area.
System Info
No response
Any additional comments?
No response
It is expected that the watch newVal and oldVal of the object are the same, because the Vue object type saves a reference, not a value. When you modify the reference of the object, you can get different newVal and oldVal. When you modify the object properties, The obtained newVal and oldVal are the same because both values point to the same object.