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
Parameter | Type | Description |
---|---|---|
|
| 响应式对象 |
|
| 键值 |
Returns
ts
{
get set value: any;
}
Ref
Name | Type |
---|---|
get value | any |
set value | void |