Blob 转json

Blob 转json

提示:Blob是二进制文件流, 常用于文件上传时

例如:文件上传流如果后端抛出的错误也会变成blob无法编译

getQuaDownload(this.applyId,this.id).then(result=>{
   if(result.type=='application/json'){
     const reader = new FileReader()
     reader.onload = function () {
       const { msg } = JSON.parse(reader.result)//此处的msg就是后端返回的msg内容
       alert(msg)
     }
     reader.readAsText(result)
   }else{
     let url = window.URL.createObjectURL(result);
     this.url=url;
   }
})