V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
爱意满满的作品展示区。
50vip

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

  •  
  •   50vip · Aug 10, 2016 · 2117 views
    This topic created in 3559 days ago, the information mentioned may be changed or developed.

    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 是支持的。

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3461 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 10:41 · PVG 18:41 · LAX 03:41 · JFK 06:41
    ♥ Do have faith in what you're doing.