es6 class定义 属性钩子

2017-05-17  本文已影响84人  奈文摩尔定律
import { Card, Icon } from 'antd';
import React from 'react';

class InfoData extends React.Component {
    // 属性只从构造器注入
    // alias
    // name <=> title
    // html_url <=> rel
    // description是描述
    // stargazers_count <=> stars
    // created_at <=> created
    // updated_at <=> updated
    // pushed_at <=> pushed
  constructor(
    title, language,
    forks, stars,
    rel, description,
    created, updated, pushed) {
    super();
    this.title = title;
    this.language = language;
    this.forks = forks;
    this.stars = stars;
    this.rel = rel;
    this.description = description;
    this.created = created;
    this.updated = updated;
    this.pushed = pushed;
  }
  set created(created) { this._created = created; }
  get created() {
    return `创建时间:${this._created}`;
  }
  set updated(updated) { this._updated = updated; }
  get updated() {
    return `更新时间:${this._updated}`;
  }
  set pushed(pushed) { this._pushed = pushed; }
  get pushed() {
    return `上次更新:${this._updated - this._pushed} years ago`;
  }
  HolderView() {
    const rightpart = (
      <div>
        {this.language}
        <Icon type={'star'} />{this.stars}
        <Icon type={'code'} />{this.forks}
      </div>
        );

    return (
      <Card
        title={this.title} extra={rightpart}
      >
        <p>{this.description}</p>
        <p>{this.created}</p>
        <p>{this.updated}</p>
        <p>{this.pushed}</p>
      </Card>
    );
  }

}


export default InfoData;

上一篇下一篇

猜你喜欢

热点阅读