Skip to content

Why doesn't the watch function work? #9715

Discussion options

You must be logged in to vote

When accessing props.reForm with watch, it will not be tracked by the effect. Therefore, you must pass a function to watch. Assuming reForm is a string like 'foo', when passed to watch, it will be handed over to the effect to track, resulting in effect(() => 'foo'). Therefore, it is essential to ensure that you pass a function that can access the reactive variable, such as () => props.reForm. This way, it will be tracked as effect(() => props.reForm), allowing normal triggering of updates.

watch(()=> props.reForm, () => {
  console.log("=====》传进来的props reform", props.reForm);
  ruleForm.value = props.reForm
})

Replies: 1 comment 1 reply

Comment options

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

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