- 先获取需要导出数据列表的日期范围
- 确定导出接口(环境地址 与 接口地址拼接)(例如:接口地址 ‘/pc/list/export’)
- 用axios设置method,url,data,headers,responseType,(注意:headers里边需要携带token,否则会报错:请登录)
- 获取到返回值后,设置文件
toExport() {
if (this.form.date == "" || this.form.date == undefined) {
this.$message.warning("请选择导出日期");
return;
}
if (this.form.date != null && this.form.date != undefined) {
this.beginTime= this.form.date[0];
this.endTime= this.form.date[1];
}
const apiUrl = process.env.API + "/pc/list/export";
axios({
method: "post",
url: apiUrl,
data: {
beginTime: this.beginTime,
endTime: this.endTime,
},
headers: {
token: ""
},
responseType: "blob"
}).then(res => {
console.log(147, res);
const link = document.createElement("a");
let blob = new Blob([res.data], {
type:
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
});
link.style.display = "none";
link.href = URL.createObjectURL(blob);
var fileName = "数据列表.xlsx";
fileName = this.videoStartDate + "至" + this.videoEnddate + fileName;
link.setAttribute("download", fileName);
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
});
}