跳到主要内容

useLastChanged

分类
导出大小
188 B
上次更改
7 个月前

记录上次更改的时间戳

演示

上次更改:5 分钟前 (1761201859697)

用法

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 记录(带有 flush: 'post'watch())。如果您想立即记录更改,请将 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>>
/** * Records the timestamp of the last change * * @see https://vueuse.org.cn/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

更新日志

v13.1.0
c1d6e - feat(shared): 确保返回类型存在 (#4659)
0a9ed - feat!: 放弃对 Vue 2 的支持,优化打包并清理 (#4349)

根据 MIT 许可证发布。