Vue 3中ref和shallowRef的引用类型在同一函数中修改值为何导致视图同步更新?-灵析社区

超好看鸭

vue3中关于ref和shallowRef声明的引用类型在同一函数中修改值,会造成shallowRef声明的视图部分也更新的问题 在视图中声明 {{ r }} {{ sr }} 修改 js代码 const r = ref({name:'111111'}) const sr = shallowRef({name:'222222'}) const change = () => { r.value.name = '333333' sr.value.name = '444444' console.log(r,sr); } 这样会造成sr也会同步更新,然后注释掉r.value.name = '333333'后,就不会。 我查询过是因为ref底层和shallowRef都会触发triggerRefValue造成视图更新,但是我还是没有理解为什么reftriggerRefValue会更新另一个数据依赖 查阅过资料,链接给出:[https://juejin.cn/post/7264503868137127971](https://link.segmentfault.com/?enc=t1usq%2FYA0UymTAGpRFuCBA%3D%3D.eyTCOfMG0UnwPXgCrPz0rjXXUNZd2nungcV3mE4e%2FF2QGALqTPkCARyoEqrSrUNo)

阅读量:206

点赞量:0

问AI
Ufoooo4U
«"https://github.com/vuejs/core/issues/5623" (https://link.segmentfault.com/?enc=QJK5S8JHc7GTJkKSqt4WGw%3D%3D.j0MXKhuvPmLoqPH%2B7tBBPW4JnXBQgoDZ0wtCwakkqMmapRV789jSSlF5eXV4gCuy)» 跟你一模一样的问题。答案楼里有人说了: «... during re-render all of the component's template is updated with the latest data.»