handleImagesUrlBefore:function(file){
var _this = this;
return new Promise(function(resolve, reject) {
var reader = new FileReader();
reader.onload = function(event) {
var image = new Image();
image.onload = function () {
var width = this.width;
var height = this.height;
if (width>695 || width < 685){
_this.$alert('图片尺寸必须在685~695之间!', '提示', {confirmButtonText: '确定'});
reject();
}
if (height >695||height< 685) {
_this.$alert('图片尺寸必须在685~695之间!', '提示', {confirmButtonText: '确定'});
reject();
}
resolve();
};
image.src = event.target.result;
}
reader.readAsDataURL(file);
});
var _this = this;
return new Promise(function(resolve, reject) {
var reader = new FileReader();
reader.onload = function(event) {
var image = new Image();
image.onload = function () {
var width = this.width;
var height = this.height;
if (width>695 || width < 685){
_this.$alert('图片尺寸必须在685~695之间!', '提示', {confirmButtonText: '确定'});
reject();
}
if (height >695||height< 685) {
_this.$alert('图片尺寸必须在685~695之间!', '提示', {confirmButtonText: '确定'});
reject();
}
resolve();
};
image.src = event.target.result;
}
reader.readAsDataURL(file);
});
}

本文介绍了一个用于验证上传图片尺寸是否符合特定范围(685至695像素)的方法。通过使用JavaScript,该方法读取文件内容并检查图像的宽度和高度。
6401

被折叠的 条评论
为什么被折叠?



