为了账号安全,请及时绑定邮箱和手机立即绑定

子组件怎么向父组件传值呢 reactjs

子组件怎么向父组件传值呢 reactjs

POPMUISE 2019-05-12 14:04:36
父组件向子组件传输用prop,那如果子组件向父组件传输怎么传呢子组件通过click事件点击,把回调里面的flag变量里面值想传给父组件,怎么传呢classChild_1extendsReact.Component{//子组件constructor(props){super(props);this.state={getName:this.props.name,getAge:this.props.age,}}click=()=>{letflag='test';}render(){const{getName,getAge}=this.state;return({`姓名:${getName}`}{`年龄:${getAge}`}clickme)}}exportdefaultChild_1;importChild_1from'./Child_1';classParentextendsReact.Component{//父组件constructor(props){super(props);this.state={}}componentDidMount(){}render(){return()}}exportdefaultParent;
查看完整描述

2 回答

?
哈士奇WWW

TA贡献1799条经验 获得超6个赞

传回调函数。在父组件里写个函数change(){}然后通过props传给子组件,再在子组件的click函数里调用this.props.change()这种东西react的官方文档里都有。
                            
查看完整回答
反对 回复 2019-05-12
  • 2 回答
  • 0 关注
  • 2482 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信