exportExcel() {
const apiUrl = "****/admin/member/out-excel"; //接口地址
axios({
method: "get", //get请求
url: apiUrl,
responseType: "arraybuffer", //responseType可选的参数有:"text"、"arraybuffer"、"blob"或"document";
//对应的返回数据为DOMString、ArrayBuffer、Blob、Document;默认参数为"text"
})
.then((res) => {
const data = res.data;
const url = window.URL.createObjectURL(
new Blob([data], {
type:
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", //注意这里地类型
})
);
const link = document.createElement("a");
link.style.display = "none";
link.href = url;
link.setAttribute("download", "用户列表.xls");
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
})
.catch((error) => {
this.$Notice.error({
title: "错误",
desc: "网络连接错误",
});
console.log(error);
});
},
【前端】点击导出excel
最新推荐文章于 2023-12-07 11:06:27 发布