1.class可定义生命周期和私有属性state。而function没有。
state:class的数据从ajax里获取,因此该位置是ajax获取数据的位置。
props:从外界传过来。
class创建组件的基本结构:
class CmdList extends React.Component{
super()//调用父类生成子类的this.
this.state = { 通过ajax获取到的数据}
render (
return
// return一个可返回的标签
CmdList //组件
CmdList //组件
)
render() 方法。 React 确定该在页面上展示什么的方式
}
ReactDOM.render(
CmdList ,//组件
document.getElementById(‘root’)。
)
function创建组件:
function CmdList(){
return
} //返回一个合法的UI结构
注:用组件时需要传递参数的必须穿,不然数据将无法显示