Category | Reactivity |
---|---|
Export Size | 237 B |
Last Changed | 9 months ago |
Related | syncRefs |
Two-way refs synchronization.
import { syncRef } from '@vueuse/core' const a = ref('a') const b = ref('b') const stop = syncRef(a, b) console.log(a.value) // a b.value = 'foo' console.log(a.value) // foo a.value = 'bar' console.log(b.value) // bar
import { syncRef } from '@vueuse/core' const a = ref('a') const b = ref('b') const stop = syncRef(a, b, { direction: 'rtl' })
import { syncRef } from '@vueuse/core' const a = ref(10) const b = ref(2) const stop = syncRef(a, b, { transform: { ltr: left => left * 2, rtl: right => right / 2 } }) console.log(b.value) // 20 b.value = 30 console.log(a.value) // 15
export interface SyncRefOptions<L, R = L> extends ConfigurableFlushSync { /** * Watch deeply * * @default false */ deep?: boolean /** * Sync values immediately * * @default true */ immediate?: boolean /** * Direction of syncing. Value will be redefined if you define syncConvertors * * @default 'both' */ direction?: "ltr" | "rtl" | "both" /** * Custom transform function */ transform?: { ltr?: (left: L) => R rtl?: (right: R) => L } } /** * Two-way refs synchronization. * * @param left * @param right */ export declare function syncRef<L, R = L>( left: Ref<L>, right: Ref<R>, options?: SyncRefOptions<L, R> ): () => void
© 2019-present Anthony Fu
Licensed under the MIT License.
https://vueuse.org/shared/syncRef/