Skip to content

useNow ​

Category
Export Size
788 B
Last Changed
6 minutes ago

Reactive current Date instance.

Demo ​

Now: Thu Nov 21 2024 08:50:51 GMT+0000 (Coordinated Universal Time)

Usage ​

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

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

Component Usage ​

This function also provides a renderless component version via the @vueuse/components package. Learn more about the usage.

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

Type Declarations ​

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.org/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>

Source ​

Source • Demo • Docs

Contributors ​

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

Changelog ​

v12.0.0-beta.1 on 11/21/2024
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
v9.11.0 on 1/17/2023
d5321 - fix(components): mark defineComponent as pure (#2623)

Released under the MIT License.