主题
useTimeAgo
响应时间。时间变化时自动更新时间显示字符串。
🌐 Reactive time ago. Automatically update the time ago string when the time changes.
示例
用法
🌐 Usage
ts
import { useTimeAgo } from '@vueuse/core'
const timeAgo = useTimeAgo(new Date(2021, 0, 1))组件用法
🌐 Component Usage
vue
<template>
<UseTimeAgo v-slot="{ timeAgo }" :time="new Date(2021, 0, 1)">
Time Ago: {{ timeAgo }}
</UseTimeAgo>
</template>非反应式用法
🌐 Non-Reactivity Usage
如果你不需要响应性,可以使用 formatTimeAgo 函数获取格式化字符串,而不是 Ref。
🌐 In case you don't need the reactivity, you can use the formatTimeAgo function to get the formatted string instead of a Ref.
ts
import { formatTimeAgo } from '@vueuse/core'
const timeAgo = formatTimeAgo(new Date(2021, 0, 1)) // string