vantUI <van-uploader> 上传图片,如何获取图片的尺寸

html代码

<van-uploader
          preview-size="300px"
          style="width:300px;display:block;margin:20px auto;"
          v-model="fileList"
          :after-read="uploadact"
          @delete="delPic"
          :preview-full-image="false"
          :max-count="1"
          upload-text="点击上传身份证正面照片"
          capture="camera"
        />

js代码

uploadact(file){
      
      var arr = file.content.split(','), mime = arr[0].match(/:(.*?);/)[1],
            bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
        while (n--) {
            u8arr[n] = bstr.charCodeAt(n);
        }
       var f = new Blob([u8arr], { type: mime });
       
      var reader = new FileReader();  
      reader.onload = function (e) {  
          var data = e.target.result;  
          //加载图片获取图片真实宽度和高度  
          var image = new Image();  
          image.onload=function(){  
              var width = image.width;  
              var height = image.height;  
              alert(width+'======'+height+"====="+f.size);  
          };  
          image.src= data;  
      };  
      reader.readAsDataURL(f); 
}
 

 

posted @ 2020-03-20 11:18  梓色心晴  Views(2680)  Comments(0Edit  收藏  举报