class Hello extends React.Component {
// 第一种、这是我一直使用的
constructor() {
this.state = {
name: 'lan'
}
}
// 第二种、这是我无意中看到的
state = {
name: 'lan'
}
}
在react16版本前使用的方式
React.createClass({
getInitialState:function(){
return {
name:'lan',
};
},
})