Skip to content

wevu / index / toRefs

函数: toRefs()

toRefs<T>(object): ToRefs<T>

定义于: packages/wevu/src/reactivity/toRefs.ts:20

将一个响应式对象转换成“同结构的普通对象”,其中每个字段都是指向原对象对应属性的 ref。

类型参数

T

T extends object

参数

object

T

待转换的响应式对象

返回

ToRefs<T>

包含若干 ref 的普通对象

示例

ts
const state = reactive({ foo: 1, bar: 2 })
const stateAsRefs = toRefs(state)

stateAsRefs.foo.value++ // 2
state.foo // 2

Released under the MIT License.