ProFormUploadButton Upload.LIST_IGNORE 不生效?


 const beforeUpload = (file: RcFile, _: RcFile[]) => {
   const isSizeValid = file.size / 1024 / 1024 < 1;

   if (!isSizeValid) {
     formRef.current?.setFieldsValue({
       descImgUrl: [],
     });
     message.error('只允许上传大小为1MB以内的图片');
   }

   return isSizeValid || Upload.LIST_IGNORE;
 };

还是会有图片显示,怎么能不显示fileList 呀啊!

阅读 1.7k
1 个回答
const beforeUpload = (file: RcFile, _: RcFile[]) => {
  return new Promise((resolve, reject) => {
    const isSizeValid = file.size / 1024 / 1024 < 1;

    if (!isSizeValid) {
      message.error('只允许上传大小为1MB以内的图片');
      reject(new Error('文件太大'));
    } else {
      resolve(file);
    }
  });
};
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进