Skip to content

Strange behavior with watch and watchEffect #6176

Discussion options

You must be logged in to vote

I run it in the SFC, click the trigger button
to trigger the window.dispatchEvent(new CustomEvent('change_ref_c')) ,the code

watch(() => refA.value, (newRefAValue) => {
  console.log('WATCH on refA change displaying refC and refA');
  console.log('refA value:', newRefAValue, 'refC value:', refC.value);
});

watchEffect(() => {
  console.log('WATCH EFFECT changing refA value and triggered on refB change only normally');
  console.log('refB value:', refB.value);
  refA.value = Math.ceil(Math.random() * 10000);
});

are all not execut.
only my add new watchEffect

watchEffect(() => {
  debugger
  // will trigger
  console.log('refC',refC.value)
})

will execut.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Danilouli
Comment options

Answer selected by Danilouli
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants