Skip to content

Function: toRef()

ts
function toRef(val: any, key: string | symbol): {
  get set value: any;
}

将响应式对象的某键值转为ref

Example

ts
const obj = reactive({ a: 1 });
const a = toRef(obj, 'a');
a.value = 2;
console.log(obj.a); //2

Parameters

ParameterTypeDescription

val

any

响应式对象

key

string | symbol

键值

Returns

ts
{
  get set value: any;
}

Ref

NameType
get valueany
set valuevoid