watchEffect doesn't trigger when it should #9773
-
I have an InputNumber custom component with a
I use a non-reactive variable ( watchEffect(() => {
// ==================================================================
// IF I ADD THIS LINE EVERYTHING WORKS
// console.log('watch effect',cFormattedValue.value)
// ==================================================================
if (elInputElement.value && !isValueFromComponent) {
setInputValue(cFormattedValue.value)
}
isValueFromComponent = false
}) The problem is that In this link I created a minimal reproduction in the Vue playground:
Am I doing something wrong? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 13 replies
-
watchEffect(() => {
// This line triggers the getter, collects dependencies correctly, and will trigger `watchEffect` upon the next update.
cFormattedValue.value
if (elInputElement.value && !isValueFromComponent) {
// If the condition here is not met during the initial execution, the computed property will be skipped, and `watchEffect` won't collect dependencies. Consequently, subsequent updates to the computed property will not trigger the `watchEffect`.
setInputValue(cFormattedValue.value)
}
isValueFromComponent = false
}) In summary, if you need to use |
Beta Was this translation helpful? Give feedback.
-
Yeah sure. That example is in fact showing the point I wanted to explain previously. There's two aspects you are missing about how reactive dependency tracking works:
In your example:
|
Beta Was this translation helpful? Give feedback.
Yeah sure. That example is in fact showing the point I wanted to explain previously.
There's two aspects you are missing about how reactive dependency tracking works:
In your example:
isExternalValue
isf…