首先在axios.post的请求中把默认的 " responseType:‘json’ " 改为" responseType:‘blob’
// 接口请求成功后 type参考本文链接
let blob = new Blob([res.data], {type: "application/msword"}); // res是接口返回的文件流
let objectUrl = URL.createObjectURL(blob);
window.location.href = objectUrl;
注:type类型参考链接(MIME(Multipurpose Internet Mail Extensions)多用途互联网邮件扩展类型_树洞菇凉的博客-CSDN博客)
如果是图片或视频把type类型
let blob = new Blob([res2.data], { type: res2.data.type });
const url = window.URL || window.webkitURL || window.moxURL;
_this.urls = url.createObjectURL(blob);