父元件向子元件傳參,子元件在 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>
)
}
}