Skip to content

wevu / index / shallowReactive

函数: shallowReactive()

shallowReactive<T>(target): T

定义于: packages/wevu/src/reactivity/reactive.ts:590

创建一个浅层响应式代理:仅跟踪第一层属性变更,不深度递归嵌套对象。

类型参数

T

T extends object

参数

target

T

待转换的对象

返回

T

浅层响应式代理

示例

ts
const state = shallowReactive({ nested: { count: 0 } })

state.nested.count++ // 不会触发 effect(嵌套对象未深度代理)
state.nested = { count: 1 } // 会触发 effect(顶层属性变更)

Released under the MIT License.