Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.6k views
in Technique[技术] by (71.8m points)

请问React Ant design pro中使用upload组件如何限制只能上传一个文件?

我用的是Beforeupload的方法,如果直接返回true或者false,文件上传不受影响,在网上找了解决方法,说是使用promise方法,但是这样点击文件上传后总是出现白屏,请问该如何解决呢?

const[upfileList,setUpfileList] = useState<[]>([])                         //上传文件的列表,只允许上传一个文件
const handleBeforeUpload=(file:any)=>{
    return new Promise((resolve,reject)=>{
      
      if(upfileList.length==0){
        setUpfileList(file)
        return resolve(true);
      }
      else{
        message.warn('仅支持上传一个文件!')
        return reject(false);
      }
    })
  }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

按照官方文档多图上传默认是 false

image.png
你可以尝试把 multiple 属性,设置为 false


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...