跳到主要内容

toReactive

分类
导出大小
269 B
上次更改
8 个月前

将 ref 转换为 reactive。也使得创建可“交换”的 reactive 对象成为可能。

用法

ts
import { 
toReactive
} from '@vueuse/core'
import {
ref
} from 'vue'
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'

类型声明

ts
/**
 * Converts ref to reactive.
 *
 * @see https://vueuse.org.cn/toReactive
 * @param objectRef A ref of object
 */
export declare function 
toReactive
<
T
extends object>(
objectRef
:
MaybeRef
<
T
>,
):
UnwrapNestedRefs
<
T
>

来源

源代码文档

贡献者

Anthony Fu
Anthony Fu
IlyaL
sibbng
三咲智子 Kevin Deng
丶远方

更新日志

v12.8.0
7432f - feat(types): 废弃 MaybeRefMaybeRefOrGetter,转而使用 Vue 的原生类型 (#4636)
v12.3.0
59f75 - feat(toValue): 废弃 @vueuse/shared 中的 toValue,转而使用 Vue 的原生函数
0a9ed - feat!: 放弃对 Vue 2 的支持,优化打包并清理 (#4349)
v10.3.0
17a72 - fix(reactiveComputed): 解包响应式类型 (#3215)

根据 MIT 许可证发布。