the ref in v-bind can not trigger compouted
Vue version
3.3.4
Link to minimal reproduction
Steps to reproduce
like the reproduction Link demo, the ref aa
in App.vue
changed,
but the computedWithProps
in Comp.vue
not be trigger
What is expected?
the computedWithProps
in Comp.vue
be trigger
What is actually happening?
the computedWithProps
in Comp.vue
not be trigger
System Info
No response
Any additional comments?
No response
maybe u should use reactive to
v-bind
the value
changed trigger aa
, aa
changed trigger props
,
so maybe i think v-bind the plain Object would be work,
but why need reactive to wrapper the v-bind object,
const vBind = { aa, }
vBind
isnt a reactive param
Can u give me more detailed explanation of this? I just want to know how it work.
The ref is set on a plain object. so it's not being unwrapped. You are not passing the ref's value to the child, you pass the ref itself to the child. so props.aa
is not the changed value of the ref, it is the ref object, and that does not change (oinly its .value
does, which you don't access in the computed)
if you actually use props.aa.value
, it works:
now, if you wrap your plain object in reactive()
, the nested ref will be unwrapped, so now v-bind
passed the value to the child Comp.
but why this is work? without reactive wrapper
This works because now your aa
ref's value returns a reactive object, and JSON.stringify
iterates over this object in the child, thereby accessing props.aa.1
during that iteration, registering it as a dep.
The ref is set on a plain object. so it's not being unwrapped. You are not passing the ref's value to the child, you pass the ref itself to the child. so
props.aa
is not the changed value of the ref, it is the ref object, and that does not change (oinly its.value
does, which you don't access in the computed)if you actually use
props.aa.value
, it works:now, if you wrap your plain object in
reactive()
, the nested ref will be unwrapped, so nowv-bind
passed the value to the child Comp.but why this is work? without reactive wrapper
This works because now your
aa
ref's value returns a reactive object, andJSON.stringify
iterates over this object in the child, thereby accessingprops.aa.1
during that iteration, registering it as a dep.
use props.aa.value
can registering it as a dep,
but why JSON.stringify(props)
not,
as you said, JSON.stringify
can iterates over this object in the child, so JSON.stringify
will iterates over props.aa
too, that means props.aa.value
will be accessing by JSON.stringify
, but why not registering it as a dep?
And this is also work, so what the different between funcA
and JSON.stringify
, or vue did some things diffenrent for JSON.stringify
?