toReactive
将 ref 转换为响应式对象。还可以创建一个“可交换”的响应式对象。
This function uses Proxy
It is NOT supported by IE 11 or below.
用法
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>
Source
贡献者
Anthony Fu
丶远方
Anthony Fu
三咲智子 Kevin Deng