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}/>
添加回答
舉報
0/150
提交
取消