在请求接口中设置responseType:'blob',可以正常下载
//封装的axios
export function downloadAttachment(params){
return request({
url:'/api/course/downloadAttachment',
params,responseType:'blob'//设置返回类型为blob
})
}
downloadAttachment({
courseId:item.courseId,//课程ID
attachmentId:item.id//课程资料ID
}).then((res)=>{
let blob = new Blob([res]);
let fileName = item.attachmentName;
let fileUrl = item.attachmentUrl;
const extName = fileUrl.substring(
fileUrl.lastIndexOf('.')
)
fileName=fileName+extName