Skip to content

useLastChanged

类别
导出体积
188 B
上次更改
5 months ago

记录最后更改的时间戳

示例

最后更改: 5 minutes ago (1758208590749)

使用方法

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

默认情况下,更改将在下一个 tick 上记录 (使用 watch() 并且 flush: 'post')。如果你想立即记录更改,请将 flush: 'sync' 作为第二个参数传递。

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

类型声明

ts
export interface 
UseLastChangedOptions
<
Immediate
extends boolean,
InitialValue
extends number | null | undefined = undefined,
> extends WatchOptions<
Immediate
> {
initialValue
?:
InitialValue
} export type
UseLastChangedReturn
=
|
Readonly
<
ShallowRef
<number | null>>
|
Readonly
<
ShallowRef
<number>>
/** * 记录最后更改的时间戳 * * @see https://vueuse.org/useLastChanged */ export declare function
useLastChanged
(
source
:
WatchSource
,
options
?:
UseLastChangedOptions
<false>,
):
Readonly
<
ShallowRef
<number | null>>
export declare function
useLastChanged
(
source
:
WatchSource
,
options
:
UseLastChangedOptions
<true> |
UseLastChangedOptions
<boolean, number>,
):
Readonly
<
ShallowRef
<number>>

源码

源码演示文档

贡献者

Anthony Fu
一纸忘忧
Robin
IlyaL
James Garbutt
yaoyin
Jady Dragon
Alex Kozack

更新日志

c1d6e - feat(shared): ensure return types exists (#4659)
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)