uploader上传前需要对图片进行高宽进行检测,具体看代码
1、获取图片宽度和高度方法,供上传前handleBeforeUpload()方法调用;
**`checkedImgWidthHeight`**(file,whenReady){
var reader = new FileReader;
reader.onload = function (evt) {
var image = new Image();
image.onload = function () {
var width = this.width;
var height = this.height;
//待加载完成后,再回调;
if (whenReady) whenReady(width, height);
};
image.src = evt.target.result;
};
reader.readAsDataURL(file);
},
2、调用检测方法checkedImgWidthHeight();由于是图片延缓加载,执行的结果为:图片已上传完毕;再调用checkedImgWidthHeight()来校验,没有达到检测图片高宽的目的,
handleBeforeUpload (file) {
debugger;
this.checkedImgWidthHeight(file,function(width,height){
var flag=width==height&&width==720;
if(!flag){
vm.$Message.warning('请将'+file.name + '修改为720X720再上传!');
}
return flag;
});
},
问题:什么方法可以解决,请指点!