Skip to content

useNow

Category
Export Size
788 B
Last Changed
15 minutes ago

响应式的当前日期实例。

Demo

当前: Thu Oct 31 2024 08:41:18 GMT+0000 (Coordinated Universal Time)

使用方法

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

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

组件使用

vue
<template>
  <UseNow v-slot="{ now, pause, resume }">
    当前时间:{{ now }}
    <button @click="pause()">
      暂停
    </button>
    <button @click="resume()">
      恢复
    </button>
  </UseNow>
</template>

类型声明

typescript
export interface UseNowOptions<Controls extends boolean> {
  /**
   * 暴露更多控制选项
   *
   * @default false
   */
  controls?: Controls
  /**
   * 更新间隔,单位为毫秒,或使用 requestAnimationFrame
   *
   * @default requestAnimationFrame
   */
  interval?: "requestAnimationFrame" | number
}
/**
 * 反应性当前 Date 实例
 *
 * @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

SourceDemoDocs

贡献者

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

变更日志

v9.11.0 on 1/17/2023
d5321 - fix(components): mark defineComponent as pure (#2623)

Released under the MIT License.