美文网首页
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定义 属性钩子

  • es6 class实现静态属性、私有属性、方法

    1.class实现静态属性 参考:ES6 class 静态属性和私有方法 es6中实现了静态方法,但是没有静态属性...

  • ES6 class与继承

    class是什么 class是定义类的方法。ES6之前用构造函数的方式定义类,ES6引入了class。 class...

  • javascript中的class

    ES5 定义构造函数 通过构造函数加属性,通过原型加方法: ES6 Class语法 class 实际上是语法糖,编...

  • JavaScript ES6 类的静态方法、属性和实例方法、属性

    类相当于实例的原型,ES6类的声明中可以定义实例方法、实例属性和静态方法。 ES6 明确规定, Class 内部只...

  • 类和对象

    类=属性+方法 属性是信息,方法是动作 class 类的意思 如何定义类? class Students #定义...

  • ES6中的变量提升

    最近在写react Native的时候发现在使用ES6定义class的时候,对其属性方法书写的时候,存在变量提升,...

  • class类的使用

    通过class关键字可以定义类,可以实现单例模式,访问器属性,静态方法,extends继承 普通写法 es6 cl...

  • react组件

    es6 的class类的继承 运用es6 class继承 通过继承React.Component类来定义一个组件

  • .

    public class 类名 { String //定义属性; //定义方...

网友评论

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

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