在组件中调用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>

 

posted on 2018-07-05 17:17  Anby-PBH  阅读(404)  评论(0编辑  收藏  举报