Skip to content

toReactive

类别
导出体积
269 B
上次更改
3 weeks ago

将 ref 转换为响应式对象。还可以创建一个 “可交换” 的响应式对象。

用法

ts
import { toReactive } from '@vueuse/core'

const refState = ref({ foo: 'bar' })

console.log(refState.value.foo) // => 'bar'

const state = toReactive(refState) // <--

console.log(state.foo) // => 'bar'

refState.value = { bar: 'foo' }

console.log(state.foo) // => undefined
console.log(state.bar) // => 'foo'

类型声明

typescript
/**
 * 将 ref 转换为 reactive。
 *
 * @see https://vueuse.org/toReactive
 * @param objectRef A ref of object
 */
export declare function toReactive<T extends object>(
  objectRef: MaybeRef<T>,
): UnwrapNestedRefs<T>

源码

源码文档

贡献者

Anthony Fu
一纸忘忧
Anthony Fu
sibbng
三咲智子 Kevin Deng
丶远方

更新日志

v12.3.0 on 1/2/2025
59f75 - feat(toValue): deprecate toValue from @vueuse/shared in favor of Vue's native
v12.0.0-beta.1 on 11/21/2024
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
v10.3.0 on 7/30/2023
17a72 - fix(reactiveComputed): unwrap reactive type (#3215)