Skip to content

useLastChanged

类别
导出大小
196 B
最近修改
2 days ago

记录最后一次更改的时间戳

🌐 Records the timestamp of the last change

示例

Last changed: 5 minutes ago (1770547389132)

用法

🌐 Usage

ts
import { 
useLastChanged
} from '@vueuse/core'
import {
nextTick
} from 'vue'
const
a
=
ref
(0)
const
lastChanged
=
useLastChanged
(
a
)
a
.
value
= 1
await
nextTick
()
console
.
log
(
lastChanged
.
value
) // 1704709379457

默认情况下,变更会在下一个时刻(watch()flush: 'post')记录。如果你想立即记录变更,可以将 flush: 'sync' 作为第二个参数传入。

🌐 By default the change is recorded on the next tick (watch() with flush: 'post'). If you want to record the change immediately, pass flush: 'sync' as the second argument.

ts
import { 
useLastChanged
} from '@vueuse/core'
const
a
=
ref
(0)
const
lastChanged
=
useLastChanged
(
a
, {
flush
: 'sync' })
a
.
value
= 1
console
.
log
(
lastChanged
.
value
) // 1704709379457