Skip to content

useNow

反应式当前 Date 实例。

¥Reactive current Date instance.

示例

Now: Fri Nov 29 2024 22:46:31 GMT+0800 (China Standard Time)

用法

¥Usage

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

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

组件用法

¥Component Usage

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

源代码

源代码示例文档

变更日志

No recent changes

VueUse 中文网 - 粤ICP备13048890号