Subscribe on changes!

shallowReactive 深层次也会被跟踪

avatar
Feb 4th 2022

Version

3.2.29

Reproduction link

stackblitz.com

Steps to reproduce

const obj = { a: 1, first: { b: 2, second: { c: 3 } } }

const state = shallowReactive(obj)

function change1() { state.a = 7 } change1()

change2() function change2() { state.first.b = 8 state.first.second.c = 9 console.log(state); }

What is expected?

修改深层属性期望视图不会跟着变化 详情看链接

Modify the deep attributes and expect that the view will not change

What is actually happening?

修改深层属性也会被跟踪视图层也会跟着变 The modification of deep attributes will also be tracked, and the view layer will change accordingly

avatar
Feb 4th 2022

You do all of the changes before the component event mounts, so there's no "update" happening.

If you did call change1 and change2 after mounted, though, the view would still update as as change1() does a reactive change.

Not sure what you are trying to demonstrate?

avatar
Feb 4th 2022

I read the example of the official website. I thought it would lose the response before mounting. I misunderstood it