跳到主要内容

useTimestamp

分类
导出大小
709 B
上次更改
8 个月前

响应式当前时间戳

演示

时间戳: 1761202149484

用法

ts
import { 
useTimestamp
} from '@vueuse/core'
const
timestamp
=
useTimestamp
({
offset
: 0 })
ts
const { 
timestamp
,
pause
,
resume
} =
useTimestamp
({
controls
: true })

组件用法

此函数还通过 @vueuse/components 包提供了一个无渲染组件版本。了解更多用法

vue
<template>
  <UseTimestamp v-slot="{ 
timestamp
,
pause
,
resume
}">
Current Time: {{
timestamp
}}
<
button
@
click
="
pause
()">
Pause </
button
>
<
button
@
click
="
resume
()">
Resume </
button
>
</UseTimestamp> </template>

类型声明

ts
export interface 
UseTimestampOptions
<
Controls
extends boolean> {
/** * Expose more controls * * @default false */
controls
?:
Controls
/** * Offset value adding to the value * * @default 0 */
offset
?: number
/** * Update the timestamp immediately * * @default true */
immediate
?: boolean
/** * Update interval, or use requestAnimationFrame * * @default requestAnimationFrame */
interval
?: "requestAnimationFrame" | number
/** * Callback on each update */
callback
?: (
timestamp
: number) => void
} /** * Reactive current timestamp. * * @see https://vueuse.org.cn/useTimestamp * @param options */ export declare function
useTimestamp
(
options
?:
UseTimestampOptions
<false>,
):
ShallowRef
<number>
export declare function
useTimestamp
(
options
:
UseTimestampOptions
<true>): {
timestamp
:
ShallowRef
<number>
} &
Pausable
export type
UseTimestampReturn
=
ReturnType
<typeof
useTimestamp
>

来源

源码演示文档

贡献者

Anthony Fu
Anthony Fu
NoiseFan
IlyaL
SerKo
IlyaL
OrbisK
vaakian X
sun0day
Waleed Khaled
sun0day
Jelf
Scott Bedard
Shinigami
wheat
Alex Kozack
Antério Vieira

更新日志

8c521 - feat(components)!: 重构组件并使其保持一致 (#4912)
0a9ed - feat!: 放弃对 Vue 2 的支持,优化打包并清理 (#4349)

根据 MIT 许可证发布。