父组件向子组件传参,子组件在 this.props 中可以接收父组件传递过来的参数。
首先定义父组件:
class Client extends Component {
render () {
const { list, type } = this.state
return (
<View>
<View className="list">
{
list.map((list,index) => {
return <Card type={type} key={index} list={list} onRefresh={this.handleRefresh.bind(this)}/>
})
}
</View>
</View>
)
}
}
子组件:
Card 组件:
class Card extends Component {
render () {
const { list = {}, type } = this.props
return (
<View className='card' onClick={this.handleChoose.bind(this)}>
姓名:{list.name} 联系方式:{list.tel}
</View>
)
}
}