有时候我们需要对上传的图片做一些限制,我在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);
获取图片上传前的宽高
原文地址:http://www.cnblogs.com/theArrow/p/7895183.html