// 上传前判断public async beforeUpload(file: any) {const is1M = file.size / 1024 / 1024 < 3; // 限制小于3Mif (!is1M) {this.$message.error('图片尺寸限制最小为270 x 270,大小不可超过3MB,比例为1:1');return false;} else {const isSize = new Promise((resolve, reject) => {const width = 270;const height = 270;const _URL = window.URL || window.webkitURL;const img = new Image();img.onload = () => {const valid = img.width >= width && img.height >= height && img.width === img.height;valid ? resolve() : reject();};img.src = _URL.createObjectURL(file);}).then(() => {return file;},() => {this.$message.error('图片尺寸限制最小为270 x 270,大小不可超过3MB,比例为1:1');return Promise.reject();},);return isSize;}}
看了很多还不如自己撸一个