实例属性

props

组件被调用时,父级传入的所有参数。

示例:

定义组件

    class HelloWorld extends React.Component {
      render() {
        return <div>hello, {this.props.name}</div>
      }
    }

调用组件

  <HelloWorld name={'React'}/>

需要特别注意的是,this.props.children.这个属性在我们平时开发中非常有用,组件嵌套、包裹会用到。

示例:

  class Root extends React.Component {
    render() {
      return <div>{this.props.children}</div>
    }
  }

嵌套使用:

  <Root>
    <div>
      children
    </div>
  </Root>

state

组件运行期间的数据。

results matching ""

    No results matching ""