因为公司安全系统策略问题,以后的博客基本会以代码为主,就很难详细的一个一个步骤讲解了(或者说是我碰到问题后思考解决问题的思路),因为太难还原步骤了。
axios
配合后台接口返回文件流下载excel(因为我项目是excel)文件,这里也可以使用post
请求,我写get
请求只是因为我项目是get
请求
//url:api地址
//params:参数
axios.get(url, {
params:params,
responseType: 'blob'
}).then(res = >{
let blob = new Blob([res], {
type: "application/vnd.ms-excel"
});
let objectUrl = URL.createObjectURL(blob);
let a = document.createElement("a");
a.href = objectUrl;
a.download = "客户";
//a.click();
//下面这个写法兼容火狐
a.dispatchEvent(new MouseEvent('click', {bubbles: true, cancelable: true, view: window}));
window.URL.revokeObjectURL(blob);
})