鍍金池/ 問答/HTML/ antd Upload組件當(dāng)multiple為true時(shí)候(也就是可以多選的時(shí)候

antd Upload組件當(dāng)multiple為true時(shí)候(也就是可以多選的時(shí)候),如何限制最多上傳圖片數(shù)量為4張;

1.antd Upload組件當(dāng)multiple為true時(shí)候(也就是可以多選的時(shí)候),如何限制最多上傳圖片數(shù)量為4張;
當(dāng)用戶一次上傳6張圖片時(shí)候 ,有個(gè)fileList受控文件列表我設(shè)置成了4,用戶看見的是4張圖片,但是實(shí)際上上傳了6張圖片。我還嘗試在onChange函數(shù)里面設(shè)置上傳的文件列表fileList,然后再beforeUpload里面獲取fileList文件列表數(shù)組的長度,當(dāng)超過4時(shí)候return false,但是每次獲取的Length都為0,有大神知道怎么解決這個(gè)問題嗎?


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>
    
回答
編輯回答
影魅

已經(jīng)解決了。。。

2017年8月19日 14:35
編輯回答
魚梓

怎么解決的啊

2018年2月3日 11:02