props属性

组建的复用性很重要

  1. // App.js
  2. class App extends React.Component {
  3. render () {
  4. let nav1 = ['首页','video', 'learn']
  5. let nav2 = ['web', 'html', 'node']
  6. // 标签换行使用小括号
  7. return (
  8. <div>
  9. <MyNav nav={nav1} title="主题1"/>
  10. <MyNav nav={nav2} title="主题2"/>
  11. </div>
  12. )
  13. }
  14. }
  • 子组件接收
  • props在子组件中不能被修改, ```javascript // mynav.js

子组件使用 this.props.key 接收父组件传值

export default class MyNav extends React.Component { render () { {/ 大括号中写 js的代码 /} return (

{ data.title }

    { this.props.nav.map((el, index) => { return
  • { el }
  • }) }
) } }

  1. - 组合
  2. this.props.children 相当于 vueslot
  3. ```javascript
  4. 父组件中
  5. <Child1 money={this.state.money}>
  6. <p>111111</p>
  7. </Child1>
  8. 子组件
  9. {
  10. this.props.children
  11. }