fix(shallowReactive): should track value if already reactive when set in shallowReactive

This commit is contained in:
Evan You 2023-12-06 15:45:15 +08:00
parent d30f6fd25f
commit 0ad8e8d94f
2 changed files with 6 additions and 5 deletions

View File

@ -110,10 +110,10 @@ function initProps(vm: Component, propsOptions: Object) {
)
}
},
true
true /* shallow */
)
} else {
defineReactive(props, key, value, undefined, true)
defineReactive(props, key, value, undefined, true /* shallow */)
}
// static props are already proxied on the component's prototype
// during Vue.extend(). We only need to proxy props defined at

View File

@ -131,7 +131,8 @@ export function defineReactive(
val?: any,
customSetter?: Function | null,
shallow?: boolean,
mock?: boolean
mock?: boolean,
observeEvenIfShallow = false
) {
const dep = new Dep()
@ -150,7 +151,7 @@ export function defineReactive(
val = obj[key]
}
let childOb = !shallow && observe(val, false, mock)
let childOb = shallow ? val && val.__ob__ : observe(val, false, mock)
Object.defineProperty(obj, key, {
enumerable: true,
configurable: true,
@ -194,7 +195,7 @@ export function defineReactive(
} else {
val = newVal
}
childOb = !shallow && observe(newVal, false, mock)
childOb = shallow ? newVal && newVal.__ob__ : observe(newVal, false, mock)
if (__DEV__) {
dep.notify({
type: TriggerOpTypes.SET,