1.antd Upload组件当multiple为true时候(也就是可以多选的时候),如何限制最多上传图片数量为4张;
当用户一次上传6张图片时候 ,有个fileList受控文件列表我设置成了4,用户看见的是4张图片,但是实际上上传了6张图片。我还尝试在onChange函数里面设置上传的文件列表fileList,然后再beforeUpload里面获取fileList文件列表数组的长度,当超过4时候return false,但是每次获取的Length都为0,有大神知道怎么解决这个问题吗?
onChange(info){
this.setState({fileList:info.fileList});
},
beforeUpload: function(file) {
if(this.state.fileList.length>4){
return false;
}
else{
this.setState({fileName:file.name});
return true;
}
const uploadButton = (
<div>
<Button>
<Icon type="upload" /> upload
</Button>
</div>
);
<Upload
name="file"
listType="picture"
fileList={fileList}
action={actionUrl}
data={reqData}
customRequest={FileRequest}
beforeUpload={this.beforeUpload}
onRemove={this.onRemoveImage}
onPreview={this.onPreviewImage}
onChange={this.onChange}
multiple={true}
>
{fileList.length >= 4? null : uploadButton}
</Upload>
已经解决了。。。