1.大小写
class Index extends React.Component{
render(){
return (
<ComponentHeader/>
);
}
}
ReactDOM.render(<Index/>,document.getElementById('example'));
注意此处ReactDOM一定不能写成ReactDom,类名Index定义了首字母大小,引用则不可忽略写成index!
2.传参不要有单引号
export default class BodyIndex extends React.Component{
render(){
var userName='smile';
var boolInput=false;
return(
<div>
<h2>这里是主体</h2>
<p>{userName==''?'You are not signed.':'name:'+userName}</p>
<p><input type='button' value='This is a button' disabled={boolInput}></input></p>
</div>
);
}
}
这里的p标签中的disabled的值{boolInput},不能写成‘{boolInput}’
3.this与箭头函数
在react中,读取服务器端的数据中的函数体中,this经过console.log出来之后变为了null,此时可以把该函数写成箭头函数的形式即可找到this的值。