TimeAgo 相对时间
注:
- 本组件没有指定样式,默认情况下可对文字样式进行自定义。
import { TaCell, TaTimeAgo, TaGroup } from '@/index'
import dayjs from 'dayjs'
const time = new Date()
const time2 = dayjs('2021-05-01', 'YYYY-MM-DD').toDate()
export default function ExpTimeAgo() {
return (
<>
<TaGroup title="基础用法">
<TaCell label="当前">
<TaTimeAgo time={time} />
</TaCell>
<TaCell label="2021-05-01">
<TaTimeAgo time={time2} />
</TaCell>
</TaGroup>
<TaGroup title="间隔">
<TaCell label="interval=2">
<TaTimeAgo time={time} interval={2} />
</TaCell>
</TaGroup>
</>
)
}
Import
import { TaTimeAgo } from 'tantalum-ui-mobile-react'
具体的引入方式可以参考引入组件。
Props
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
time | Date | string | number | 99 | 否 | 需要对比的时间,可以是 Date 类型,时间戳,或者 '2021-05-01' 之类的 string 类型(需要搭配 formatTemplate 使用) |
formatTemplate | string | 否 | time 为 string 类型对应的解析模板,模板规则参考 Dayjs | |
interval | number | 60 | 否 | 自动更新的间隔,单位:秒 |