亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

子組件怎么向父組件傳值呢 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 關注
  • 2534 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號