コンテンツにスキップ

useTimestamp

カテゴリー
エクスポートサイズ
817 B
最終変更
先週

リアクティブな現在のタイムスタンプ

デモ

タイムスタンプ: 1732766349077

使い方

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.dokyumento.jp/useTimestamp
 * @param options
 */
export declare function useTimestamp(
  options?: UseTimestampOptions<false>,
): Ref<number>
export declare function useTimestamp(options: UseTimestampOptions<true>): {
  timestamp: Ref<number>
} & Pausable
export type UseTimestampReturn = ReturnType<typeof useTimestamp>

ソース

ソースデモドキュメント

貢献者

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

変更履歴

v12.0.0-beta.1 2024/11/21
0a9ed - feat!: Vue 2 のサポートを削除、バンドルを最適化し、クリーンアップ (#4349)
v9.11.0 2023/01/17
d5321 - fix(components): defineComponentをpureとしてマーク (#2623)
v9.3.0 2022/09/26
33dbc - feat: useInterval、useTimeout & useTimestamp のオプションのコールバック (#2240)

MITライセンスの下でリリースされています。