主题
useTimeAgoIntl
响应式开发,支持国际化。当时间改变时自动更新 time ago 字符串。由 Intl.RelativeTimeFormat
提供支持。
¥Reactive time ago with i18n supported. Automatically update the time ago string when the time changes. Powered by Intl.RelativeTimeFormat
.
示例
用法
¥Usage
js
import { useTimeAgoIntl } from '@vueuse/core'
const timeAgoIntl = useTimeAgoIntl(new Date(2021, 0, 1))
非反应式用法
¥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.
js
import { formatTimeAgoIntl } from '@vueuse/core'
const timeAgoIntl = formatTimeAgoIntl(new Date(2021, 0, 1)) // string