//导出
async btnClick(type, data) {
const res = await exportMultiSheet();
// 构造一个blob对象来处理数据,并设置文件类型、type为导出的文件类型 以excel为demo
const blob = new Blob([res], { type: "application/vnd.ms-excel" });
console.log(blob);
const href = URL.createObjectURL(blob); // 创建新的URL表示指定的blob对象
const a = document.createElement("a"); // 创建a标签
a.style.display = "none";
a.href = href; // 指定下载链接
//设置指定元素上的某个属性值。如果属性已经存在,则更新该值
a.setAttribute("download", "导出文件.xlsx");
a.click(); // 触发下载
URL.revokeObjectURL(a.href); // 释放URL对象
},
接口
// 导出
export const exportMultiSheet= (data) => {
return axios({
url: `${baseUrl}/chrt/exportMultiSheet`,
method: 'post',
responseType:'blob'
})
}