2022-06-27 antd 组件upload方法onChange没反应
前言:报错如题↑↑,点击上传图片,监听组件upload并把成功上传的图片赋值给变量。
组件代码:
<Upload multiple={true} action={} data={} name="image" fileList={fileList} accept="image/gif, image/jpeg, image/jpg, image/png" onChange={()=>this.handleChange}> {fileList.length > 0 ? null : uploadButton} </Upload>
原因:前头函数this指向问题
解决方案:取消箭头函数,直接写,即:
<Upload multiple={true} action={} data={} name="image" fileList={fileList} accept="image/gif, image/jpeg, image/jpg, image/png" onChange={this.handleChange} > {fileList.length > 0 ? null : uploadButton} </Upload>
注:
antd v3
react 16.3.1