1.在做一个pdf导出功能的时候卡主了,是可以下载的,但是下载后的pdf文件打开是空白的,用postman测试下载后台的pdf文件是可以正常打开并且有内容的
2.下载代码:
downLoadResume(){
axios.post('url',{
responseType: 'arraybuffer'
}).then((res)=>{
console.log(res);
if(res.status == 200){
let blob = new Blob([res.data], {
type: `application/pdf;charset-UTF-8`//word文档为msword,pdf文档为pdf
});
let objectUrl = URL.createObjectURL(blob);
console.log(objectUrl);
let downEle = document.createElement("a");
let fname = `download`; //下载文件的名字
downEle.href = objectUrl;
downEle.setAttribute("download", fname);
document.body.appendChild(downEle);
downEle.click();
}
// fileDownload(res.data,'resume.pdf')
}).catch((err)=>{
console.log(err);
})
}
为方便我用
fetch
试了下,一点问题都没有。你把你的文件做个md5
和源文件对比下是不是一样,你怕只是单纯的打不开pdf
文件吧。