// 将返回的流数据转换为url
export function getObjectURL(file, type) {
return window.URL.createObjectURL(new Blob([file], { type }))
}
// base64转url
export function base64ToUrl(data, type) {
let base64 = data
let bstr = atob(base64)
let n = bstr.length
let u8arr = new Uint8Array(n)
while (n--) {
u8arr[n] = bstr.charCodeAt(n)
}
//确定解析格式
let blob = new Blob([u8arr], { type:'application/pdf;chartset=UTF-8' })
let url = window.URL.createObjectURL(blob)
return url
}
this.pdfUrl = getObjectURL(res.data, 'application/pdf;chartset=UTF-8')
返回的数据格式:
![在这里插入图片描述](https://img-blog.csdnimg.cn/b1278743761a410b875d2fe2b65c8912.png)
效果图:
![在这里插入图片描述](https://img-blog.csdnimg.cn/a8fdef60136b47e580be30c0c7cb0302.png)