1 <el-upload
2 class="avatar-uploader"
3 :action="action"
4 :show-file-list="false"
5 :before-upload="beforeAvatarUpload">
6 <i class="el-icon-plus avatar-uploader-icon"></i>
7 </el-upload>
1 methods: {
2 beforeAvatarUpload(file) {
3 let width = 750;
4 let height = 1642;
5 const isSize = new Promise(function (resolve, reject) {
6 let _URL = window.URL || window.webkitURL;
7 let img = new Image();
8 img.onload = function () {
9 let valid = img.width == width && img.height == height;
10 valid ? resolve() : reject();
11 }
12 img.src = _URL.createObjectURL(file);
13 }).then(() => {
14 return file;
15 }, () => {
16 this.$message({
17 message: `上传图片尺寸只能是${width}*${height}px!请重新选择!`,
18 type: 'warning'
19 });
20 return false;//必须加上return false; 才能阻止
21 })
22 return isSize;
23 }
24 },