Cannot read property 'setState' of undefined错误分析

在组件中调用handlePreview时候出现这样的错误,主要在使用es6的时候,this的指向发生了变化,所以可以使用箭头函数或者.bind绑定this来解决;

handlePreview=(file)=>{
        this.setState({
            previewImage:file.url || file.thumbUrl,
            previewVisible:true
        })
    }
<Upload  action="//jsonplaceholder.typicode.com/posts/"
                         listType="picture-card"
                         fileList={fileList}
                         onPreview={this.handlePreview} //上传时的样子
                         onChange ={this.handleChange} //点击预览之后的回调
  ></Upload>
原文地址:https://www.cnblogs.com/naniandongzhi/p/9269472.html