1. 请求头添加 responseType: 'blob' 或 responseType: 'arraybuffer';
如果请求头没用,那就是封装的axios问题;
2.使用原生的axios,不做封装处理,更改responseType类型为 blob;
import axios from 'axios' // 引入原生的axios,不作封装处理
await axios({
method: 'GET',
headers: { token },
url: `api/export`,
responseType: 'blob' // 更改responseType类型为 blob
}).then(res => {
// 转换pdf
const blob = new Blob([res.data], { type: 'application/pdf' });
const url = window.URL.createObjectURL(blob);
window.open(url)
}).catch(err => {
console.log(err)
})
3.可以打印下结果,查看request下的responseType是否是blob。如果是空,检查下项目是不是引入了mock,把它注释掉就行了。


4. 如果是uni.request请求接口,不妨试试将 responseType: "blob"改成 responseType: "arraybuffer";
1万+

被折叠的 条评论
为什么被折叠?



