Skip to content

syncRef

类别
导出大小
641 B
最近修改
2 days ago
相关

双向参考同步。

🌐 Two-way refs synchronization.

示例

用法

🌐 Usage

ts
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

一向

🌐 One directional

ts
import { 
syncRef
} from '@vueuse/core'
const
a
=
ref
('a')
const
b
=
ref
('b')
const
stop
=
syncRef
(
a
,
b
, {
direction
: 'rtl' })

自定义变换

🌐 Custom Transform

ts
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