Skip to content

useSyncRef

useSyncRef(source, options?): Ref<any>

Two-way refs synchronization.

参数

NameTypeDescription
sourceRef<any>要同步的源引用。
optionsany定义如何同步的选项。

返回值

Ref<any>

  • 与源引用同步的新引用。

See

syncRef

示例

ts
// 之前
const a = ref('a')
const b = ref('b')

const stop = syncRef(a, b)

// 现在
const a = ref('a')
const b = useSyncRef(a)

b.value = 'foo'
console.log(a.value) // foo

a.value = 'bar'
console.log(b.value) // bar

源码

use-sync-ref.js