V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
50vip
V2EX  ›  分享创造

[开源] timeago-react 简单高效的实时组件 '3 hours ago'

  •  
  •   50vip · 2016-08-10 13:15:56 +08:00 · 1604 次点击
    这是一个创建于 2832 天前的主题,其中的信息可能已经有所发展或是发生改变。

    timeago-react

    一个非常简单的 react 组件,用于见时间格式化成 *** time ago 格式。 eg: '3 hours ago'。

    实时渲染比较高效,很足 timeago 组件是每秒渲染一次,实际上对于时间是小时级别的,只需要每小时变化一次即可,同理,对于 3 years ago 的时间,是需要每年变化一次即可。

    The component based on timeago.js.本身只有2kb大小,所以这个组件是非常轻量级的,不会动辄占用几十kb,甚至依赖jquery。

    github 地址:https://github.com/hustcc/timeago-react

    Build Status npm npm npm

    1. 安装

    npm install timeago-react
    

    2. 使用

    非常简单。

    import React from 'react';
    import TimeAgo from 'timeago-react'; // var TimeAgo = require('timeago-react');
    
    <TimeAgo
      date={'2016-08-08 08:08:08'} 
      local='zh_CN' />
    

    3. 组件属性

    • date (required, string / Date / timestamp)

    将要被格式化的时间,可以是时间格式的字符串,时间对象,也可以是时间戳。

    • live (optional, boolean)

    是否实时渲染,默认为 true 。

    • className (optional, string)

    组件的 class 属性,可以用来设置 css 样式。

    • local (optional, string)

    语言, 默认是 en. zh_CN and en 是支持的。

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2675 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 15:45 · PVG 23:45 · LAX 08:45 · JFK 11:45
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.