在项目中遇到“文件流下载ppt文件无法打开或文件已损坏”这种情况,我也是查阅资料来一个排查问题的汇总
1.要设置responseType,在接口传参的时候传参过去
2.注意接口返回的new Blob中的数据是res还是res.data,有时候接口返回数据的封装层次不一样,我们拿到的数据也不一样
request({
url: "填入接口地址url",
method: 'post',
// responseType: 'arraybuffer',
responseType: 'blob',
data: qs.stringify(params),
}).then(res => {
let link = document.createElement('a')
link.download = fileName
link.style.display = 'none';
link.href = window.URL.createObjectURL(new Blob([res.data]))
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
})