前端用gblob处理二进制pdf文件预览

代码封装请求注意

export function certificatePdf(data) {
  return request({
    url: '/report/raceCertificatePdf',
    method: 'post',
    data:data,
    responseType: 'blob'
  })
}

请求

certificatePdf(this.ids).then(res => {
          console.log(res);
          var binaryData = [];
          binaryData.push(res);
          let blob = new Blob(binaryData, {
            type: 'application/pdf;chartset=UTF-8'
          });
          console.log(blob);
          let href = window.URL.createObjectURL(blob); //创建下载的链接
          window.open(href)
          return
        })
原文地址:https://www.cnblogs.com/ddqyc/p/15791120.html