vue 项目中excel文件导出:
exportData() {//点击方法名称
jjrExport(this.years).then(res => {//this.years为请求参数
console.log(res);
const type = "application/vnd.ms-excel;charset=utf-8";//excel文件
const blob = new Blob([res], { type: type });
const createA = document.createElement("a");
const href = window.URL.createObjectURL(blob);
createA.href = href;
createA.download = `${new Date().Format("yyyy")}节假日数据统计.xls`;
document.body.appendChild(createA);
createA.click();
document.body.removeChild(createA);//下载完成后移除标签
window.URL.revokeObjectURL(href);//释放url
})
}
接口返回数据示例:
- Blob {size: 5120, type: "application/vnd.ms-excel"}
- size: 5120
- type: "application/vnd.ms-excel"
- __proto__: Blob
- size: (...)
- type: (...)
- slice: ƒ slice()
- stream: ƒ stream()
- text: ƒ text()
- arrayBuffer: ƒ arrayBuffer()
- constructor: ƒ Blob()
- Symbol(Symbol.toStringTag): "Blob"
- get size: ƒ size()
- get type: ƒ type()
- __proto__: Object