上传图片及获取原始图片宽高

  • 上传的组件,略
  • 上传图片组件的页面应用

  • 获取原始图片的尺寸并添加限制
    在onload的方法中,image.width=this.naturalWidth
headUpload: function(url) {
    let that = this,
        image = new Image();
    image.src = url;
    if(url)  that.$refs.formData.clearValidate('img');
            that.formData.img = url;
      console.log('headUpload=',url,'image',image)
    image.onload=function(){        
    console.log('width==',image.width,this.naturalWidth,'height==',this.naturalHeight)
      if(this.naturalWidth/this.naturalHeight!=2){
         that.headImgStatus = false;
        that.$message.warning('图片的宽高比例为2:1');
      }
    };
  },

你可能感兴趣的:(上传图片及获取原始图片宽高)