赞
踩
以axios请求,下载xls文件为例
- export function download() {
- return request({
- url: "/api",
- method: "GET",
- headers: { "Content-Type": "application/xls" },
- responseType: "blob",
- });
- }
方法中接收到二进制数据,创建链接并下载
- const blob = new Blob([res.data], {
- type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8",
- });
- const link = document.createElement("a");
- link.href = window.URL.createObjectURL(blob);
- link.download = "车辆列表.xlsx" || "file";
- link.click();
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。