判断文件大小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(); } ); },
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(); } ); },
判断出上传图片的宽高
标签:文件大小,resolve,return,img,file,reject,上传,图片 From: https://www.cnblogs.com/bljjs/p/17144054.html