Skip to content

useTimestamp

类别
导出体积
709 B
上次更改
7 months ago

响应式的当前时间戳

示例

时间戳: 1757949503303

用法

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

组件用法

vue
<template>
  <UseTimestamp v-slot="{ 
timestamp
,
pause
,
resume
}">
当前时间:{{
timestamp
}}
<
button
@
click
="
pause
()">
暂停 </
button
>
<
button
@
click
="
resume
()">
恢复 </
button
>
</UseTimestamp> </template>

类型声明

ts
export interface 
UseTimestampOptions
<
Controls
extends boolean> {
/** * 暴露更多控制选项 * * @default false */
controls
?:
Controls
/** * 添加到值的偏移量 * * @default 0 */
offset
?: number
/** * 立即更新时间戳 * * @default true */
immediate
?: boolean
/** * 更新间隔,或使用 requestAnimationFrame * * @default requestAnimationFrame */
interval
?: "requestAnimationFrame" | number
/** * 每次更新时的回调函数 */
callback
?: (
timestamp
: number) => void
} /** * 响应式的当前时间戳。 * * @see https://vueuse.org/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
IlyaL
SerKo
IlyaL
OrbisK
vaakian X
sun0day
Waleed Khaled
sun0day
Jelf
Scott Bedard
Shinigami
wheat
Alex Kozack
Antério Vieira

更新日志

8c521 - feat(components)!: refactor components and make them consistent (#4912)
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)