Why doesn't the watch function work? #9715
-
I define a ref in the parent component and then pass it to the child component:
Child components receive reFrom via defineProps
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
When accessing watch(()=> props.reForm, () => {
console.log("=====》传进来的props reform", props.reForm);
ruleForm.value = props.reForm
}) |
Beta Was this translation helpful? Give feedback.
When accessing
props.reForm
withwatch
, it will not be tracked by theeffect
. Therefore, you must pass a function towatch
. AssumingreForm
is a string like'foo'
, when passed towatch
, it will be handed over to theeffect
to track, resulting ineffect(() => '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 aseffect(() => props.reForm)
, allowing normal triggering of updates.