useTimestamp
响应式当前时间戳
Demo
时间戳: 1741578424305
用法
js
import { useTimestamp } from '@vueuse/core'
const timestamp = useTimestamp({ offset: 0 })
js
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>
类型声明
typescript
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>
源码
贡献者
更新日志
v12.0.0-beta.1
于 2024/11/21