コンテンツにスキップ

useNow

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

リアクティブな現在の日付インスタンス。

デモ

現在: 2024年11月28日木曜日 03:59:07 GMT+0000 (協定世界時)

使い方

js
import { useNow } from '@vueuse/core'

const now = useNow()
js
const { now, pause, resume } = useNow({ controls: true })

コンポーネントの使用法

この関数は、@vueuse/components パッケージを通じてレンダーレスコンポーネントバージョンも提供します。使用法について詳しくはこちら

vue
<template>
  <UseNow v-slot="{ now, pause, resume }">
    Now: {{ now }}
    <button @click="pause()">
      Pause
    </button>
    <button @click="resume()">
      Resume
    </button>
  </UseNow>
</template>

型宣言

typescript
export interface UseNowOptions<Controls extends boolean> {
  /**
   * Expose more controls
   *
   * @default false
   */
  controls?: Controls
  /**
   * Update interval in milliseconds, or use requestAnimationFrame
   *
   * @default requestAnimationFrame
   */
  interval?: "requestAnimationFrame" | number
}
/**
 * Reactive current Date instance.
 *
 * @see https://vueuse.dokyumento.jp/useNow
 * @param options
 */
export declare function useNow(options?: UseNowOptions<false>): Ref<Date>
export declare function useNow(options: UseNowOptions<true>): {
  now: Ref<Date>
} & Pausable
export type UseNowReturn = ReturnType<typeof useNow>

ソース

ソースデモドキュメント

貢献者

Anthony Fu
Anthony Fu
Maher
vaakian X
sun0day
Shinigami
wheat
Alex Kozack
Antério Vieira

変更履歴

v12.0.0-beta.1 2024/11/21
0a9ed - feat!: Vue 2 のサポートを終了、バンドルを最適化、クリーンアップ (#4349)
v9.11.0 2023/1/17
d5321 - fix(components): defineComponent を pure としてマーク (#2623)

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