美文网首页
es6 class定义 属性钩子

es6 class定义 属性钩子

作者: 奈文摩尔定律 | 来源:发表于2017-05-17 10:59 被阅读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;
    
    

    相关文章

      网友评论

          本文标题:es6 class定义 属性钩子

          本文链接:https://www.haomeiwen.com/subject/yoqdxxtx.html