props属性
组建的复用性很重要
// App.js
class App extends React.Component {
render () {
let nav1 = ['首页','video', 'learn']
let nav2 = ['web', 'html', 'node']
// 标签换行使用小括号
return (
<div>
<MyNav nav={nav1} title="主题1"/>
<MyNav nav={nav2} title="主题2"/>
</div>
)
}
}
- 子组件接收
- 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 } }) }
- 组合
this.props.children 相当于 vue中slot
```javascript
父组件中
<Child1 money={this.state.money}>
<p>111111</p>
</Child1>
子组件
{
this.props.children
}