triggerRef doesn't trigger the callback of a simple function watch source
Vue version
3.3.4
Link to minimal reproduction
Steps to reproduce
Click the button, watch the console's logs
What is expected?
'watch function' should be logged
What is actually happening?
it doesn't
System Info
No response
Any additional comments?
No response
The first case does not work because the value has not changed (always msg.value).
The second case works because a new return value is obtained (oldValue - msg.value
, newValue - [msg.value]
)
The first case does not work because the value has not changed (always msg.value). The second case works because a new return value is obtained (oldValue - `msg.value`, newValue - `[msg.value]`)
I thought I can trigger the effect without changing the value by using the triggerRef
. And it does trigger when watch the shallowRef directly or use watchEffect. But I don't understand the difference you talked about the two cases above. The array case, both newValue and oldValue are array.
I thought I can trigger the effect without changing the value by using the triggerRef.
The watcher's getter function is being triggered by triggerRef
. the callback however, is only being run if the watch's getter function returns a different value.
The array example works because each time the getter runs, it returns a new array - that array may contain the same value as the one before, but its a differerent array. So the callback is being run.
I thought I can trigger the effect without changing the value by using the triggerRef.
The watcher's getter function is being triggered by
triggerRef
. the callback however, is only being run if the watch's getter function returns a different value.The array example works because each time the getter runs, it returns a new array - that array may contain the same value as the one before, but its a differerent array. So the callback is being run.
Alright, I understand that now, thank you!