Skip to content

useSyncRefs

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

Keep target refs in sync with a source ref

参数

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

返回值

Ref<any>

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

See

syncRefs

示例

ts
// 之前
const source = ref('hello')
const target = ref('target')

const stop = syncRefs(source, target)

// 现在
const source = ref('hello')
const target = useSyncRefs(source)

console.log(target.value) // hello

source.value = 'foo'
console.log(target.value) // foo

target.value = 'bar'
console.log(source.value) // foo,反之不会同步

源码

use-sync-refs.js