Appearance
useSyncRefs
▸ useSyncRefs(source, options?): Ref<any>
Keep target refs in sync with a source ref
参数
| Name | Type | Description |
|---|---|---|
source | Ref<any> | 要同步的源引用。 |
options | SyncRefsOptions | 定义如何同步的选项。 |
返回值
Ref<any>
- 与源引用同步的新引用。
See
示例
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,反之不会同步