当报错这个的时候就要看函数是否在行内绑定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

相关文章: