导出excel
// 导出excel请求
const specialService = axios.create({
baseURL: base,
timeout: 30000,
headers: {
'Content-Type': 'application/json; application/octet-stream',
'Authorization': sessionStorage.getItem('token')
},
responseType: 'arraybuffer'
});
getExcel(url, data) {
return specialService.get(url, {
params: data
});
}
接口返回
console.log(res);
const date = new Date();
const y = date.getFullYear();
let m = date.getMonth() + 1;
m = m < 10 ? `0${m}` : m;
let d = date.getDate();
d = d < 10 ? `0${d}` : d;
let h = date.getHours();
h = h < 10 ? `0${h}` : h;
let minute = date.getMinutes();
let second = date.getSeconds();
minute = minute < 10 ? `0${minute}` : minute;
second = second < 10 ? `0${second}` : second;
const name = `用户列表-${y}${m}${d}${h}${minute}${second}`;
const link = document.createElement("a");
const blob = new Blob([res.data], {
type: "application/vnd.ms-excel",
});
link.style.display = "none";
link.href = URL.createObjectURL(blob);
link.setAttribute("download", `${name}.csv`);
document.body.appendChild(link);
link.click();
document.body.removeChild(link);