获取图片上传前的宽高

有时候我们需要对上传的图片做一些限制,我在vue里面用的

var reader = new FileReader();
var that = this;
reader.onload = function(e){
//console.log(e);
    var img = new Image();
    img.src = e.target.result;
    img.onload = function(){
console.log(
this.width, " ", this.height); if(this.width != 500 || this.height != 158){   that.$message.error('图片宽高不符合尺寸!!');   that.$refs.upload.abort();   that.$refs.upload.clearFiles();   } } } var url = reader.readAsDataURL(file);

 

posted @ 2017-11-25 14:18  Tim.Arrow  阅读(399)  评论(0编辑  收藏  举报