方法一:
后端返回的数据是文件流:
const a = document.createElement('a');
document.body.appendChild(a);
// URL.createObjectURL()方法会根据传入的参数创建一个指向该参数对象的URL
a.href = URL.createObjectURL(new Blob([res.data.stream_file], {
type: 'application/msword'
})); // type是Blob类型 [type类型参考](https://blog.csdn.net/weixin_43550766/article/details/121991772)
a.download = '文件名';
a.click();
// URL.revokeObjectURL()方法会释放掉URL.createObjectURL()方法创建的URL,当你已经使用过了这个URL,要让浏览器知道这个URL已经不再需要指向对应的文件,就需要调用这个方法。
URL.revokeObjectURL(a.href);
document.body.removeChild(a);
方法二:
后端返回的数据是文件链接:
window.open('链接', '_blank');