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

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

react通過子組件向父組件傳值修改父組件state失敗

react通過子組件向父組件傳值修改父組件state失敗

守著星空守著你 2018-08-02 17:28:25
react通過子組件向父組件props的函數傳參,傳值,修改父組件state,父組件報錯this.setState is not a function子組件:fetch(``,{            method:'GET',            mode:'cors',        }).then(function(response){            _this.setState({                loading:false            })            return response.json().then(function(res){                if(res.content.length===0){                    _this.props.handleFetch("false"); //在這里給父組件傳值                }                _this.setState({                    newsList:res.content,                    totalPages:res.totalPages                });            });            父組件:constructor(props){    super(props);    this.state = {        keyword:this.props.match.params.id,        result:"true",        _isMounted:true    };    this.handleFetch.bind(this)}handleFetch(status){    console.log(status) //可以打印 出傳來的false    this.setState({        result:status    })}<NewsList type="search" id={this.state.keyword} handleFetch={this.handleFetch}/>
查看完整描述

2 回答

?
心有法竹

TA貢獻1866條經驗 獲得超5個贊

<NewsList type="search" id={this.state.keyword} handleFetch={this.handleFetch.bind(this)}/>

查看完整回答
反對 回復 2018-08-06
?
喵喵時光機

TA貢獻1846條經驗 獲得超7個贊

constructor中的

this.handleFetch.bind(this)

改為

this.handleFetch = this.handleFetch.bind(this)


查看完整回答
反對 回復 2018-08-06
  • 2 回答
  • 0 關注
  • 2202 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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