Skip to content

useNow

类别
导出体积
676 B
上次更改
2 months ago

响应式的当前日期实例。

示例

当前: Thu Sep 18 2025 15:21:16 GMT+0000 (Coordinated Universal Time)

使用方法

ts
import { 
useNow
} from '@vueuse/core'
const
now
=
useNow
()
ts
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>

类型声明

ts
export interface 
UseNowOptions
<
Controls
extends boolean> {
/** * 暴露更多控制选项 * * @default false */
controls
?:
Controls
/** * 立即开始计时 * * @default true */
immediate
?: boolean
/** * 更新间隔,单位为毫秒,或使用 requestAnimationFrame * * @default requestAnimationFrame */
interval
?: "requestAnimationFrame" | number
} /** * 反应性当前 Date 实例 * * @see https://vueuse.org/useNow * @param options * * @__NO_SIDE_EFFECTS__ */ 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
一纸忘忧
SerKo
Anthony Fu
IlyaL
Scott Bedard
OrbisK
Maher
vaakian X
sun0day
Shinigami
wheat
Alex Kozack
Antério Vieira

更新日志

8c521 - feat(components)!: refactor components and make them consistent (#4912)
d32f8 - refactor: add @__NO_SIDE_EFFECTS__ annotations to all pure functions (#4907)
44660 - feat: expose immediate option (#4768)
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)