react父组件向子组件传值问题

it_leaner 2017-04-26 07:56:30
import React from 'react'
class Parent extends React.Component{
constructor(props){
super(props)
this.state={
text:'content'
}
}
render(){
return <div>
<h3>fu</h3>
<input type="button" value="in_theaters" onClick={()=>{this.change('in_theaters')}}/>
<input type="button" value="coming_soon" onClick={()=>{this.change('coming_soon')}}/>
<input type="button" value="top250" onClick={()=>{this.change('top250')}}/>
<hr/>
<Son></Son>
</div>
}
change=(str)=>{
this.setState({
text:str
})
}
}
class Son extends React.Component{
render(){
return <div>
<h2>zi</h2>
<p>当前的电影类型:{this.props.text}</p>
</div>
}
}
export default Parent;
...全文
376 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
li905663280 2017-04-26
  • 打赏
  • 举报
回复
<Son text={this.state.text}></Son>

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧