首页 > 其他分享 >图片上传限制文件大小

图片上传限制文件大小

时间:2023-02-22 13:58:50浏览次数:37  
标签:文件大小 resolve return img file reject 上传 图片

判断文件大小    
beforeUpload(file,) { return new Promise((resolve, reject) => { const fileSize = file.size / 1024 / 1024; if (fileSize < 3) { resolve(); } else { this.$message.warning('文件大小不能超过3M!'); reject(); } }).then( () => { return file; }, () => { return Promise.reject(); } ); },
判断出上传图片的宽高
    onBeforeUpload(file, w, h) {         return new Promise((resolve, reject) => {         let isSize;       const img = new Image();       const _URL = window.URL || window.webkitURL;     img.onload = () => {     isSize = img.width === w && img.height === h;     if (!isSize) {       this.$message.error('请检查图片宽*高是否符合要求。');       this.fundForm.fileList = [];     reject();     } else {       resolve();     }   };     img.src = _URL.createObjectURL(file);   }).then(     () => {     return file;     },     () => {     return Promise.reject();     }   ); },
 

 

标签:文件大小,resolve,return,img,file,reject,上传,图片
From: https://www.cnblogs.com/bljjs/p/17144054.html

相关文章