zoukankan      html  css  js  c++  java
  • react 部分ES6写法

    react+react-router+antd 栗子:https://github.com/Aquarius1993/reactApp
    模块:
    1. 引入模块
    import React from 'react';
    2. 导出组件
    export default App;
    3. 引用
    import App from './APP.jsx';
    组件:
    1.  结构
    class App extends React.Component {}
    2. 设置state
    用 constructor 代替 getInitialState:
    getInitialState() {
    return {liked: false};
    }
    ======》
    constructor(props) {
    super(props);
    this.state = {
    liked: false
    }
    }
    3. 设置默认Props
    class LinkButton extends React.Component {
    getDefaultProps() {
     return {
         name: 'Runoob'
        };
    }
     
    }
    =====》
    LinkButton.defaultProps = {name: 'Runoob'}
    4.  props验证propTypes
    propTypes: {
       title: React.PropTypes.string.isRequired,
     },
    ======》
    LinkButton.propTypes = {title: React.PropTypes.string.required}
    5. 事件绑定
    <p onClick={this.handelClick}>点我切换状态</p>
    =======》
    <p onClick={e=>this.handelClick(e)}>点我切换状态</p> 
  • 相关阅读:
    三种方法
    渐渐明白
    出手的时候到了
    URL OpenDocument
    熟练使用IDT
    时间快到了
    还是这样
    接口的多态性
    接口(interface)的使用
    抽象类(abstract class)与抽象方法
  • 原文地址:https://www.cnblogs.com/lhy-93/p/6343326.html
Copyright © 2011-2022 走看看