useTimestamp
響應式當前時間戳記
示範
時間戳記: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.dev.org.tw/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