赞
踩
antd 组件库使用时onChange只会执行到 uploading状态 解决办法
问题: 1.6.5版本 Upload控件onChange方法只会执行一次,且info.file.status一直为uploading,http请求正常,返回200。
降级为1.6.4之后正常使用,uploading之后info.file.status为done
这个方法在onChange时触发
handleUploaderChange = (info) => { let fileList = [...info.fileList]; fileList = fileList.slice(-2); // 2. Read from response and show file link fileList = fileList.map(file => { if (file.response) { // Component will show file.url as link file.url = file.response.url; console.log(222,fileList) } return file; }); this.setState({ fileList }); console.log(999,fileList) };
如何使用
<Upload
accept="image/jpeg,image/jpg,image/png"
action={上传路径}
listType="picture"
fileList={fileList}
beforeUpload={beforeUpload} // 用于判断文件格式
onPreview={this.handlePreview}
onChange={this.handleUploaderChange} // 上传触发事件
>
<div className={`${styles.uploadFile}`}>
点击上传
</div>
</Upload>
官方文档 https://ant.design/components/upload/#components-upload-demo-fileList
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。