
正文
react报错this.setState is not a function
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
当报错这个的时候就要看函数是否在行内绑定this,或者在constructor中绑定this。
我这里犯的错误的是虽然我在constructor中绑定了this,但是语法写的不正确。
错误示范:
constructor(props){
super(props);
this.state = {
keyword:this.props.match.params.id,
result:"true",
_isMounted:true
};
this.handleFetch.bind(this) //看这里
}
正确写法:
constructor(props){
super(props);
this.state = {
keyword:this.props.match.params.id,
result:"true",
_isMounted:true
};
this.handleFetch=this.handleFetch.bind(this) //这里一定要写等于
}
问题见这里:https://segmentfault.com/q/1010000015903657







![【电子书】[职业技术] 《深入react技术栈》[陈屹][epub+mobi+azw3] 【电子书】[职业技术] 《深入react技术栈》[陈屹][epub+mobi+azw3]](https://www.04ip.com/template/qe/style/noimg/5.jpg)