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>