Vue 调用后台接口导出Excel
vue 调用后台接口生成 Excel
咱也不会前端,就是现学现卖。
Js
export function exportOnlyB(reportId) {
return request({
url: "/bbs/regtech/relationapi/exportOnlyB?reportId=" + reportId,
method: "get",
responseType: "blob",
});
}
Vue
methods
exportComparisonResult() {
var reportId = this.getComparisonResultParams.reportId;
exportComparisonResult(reportId).then((res) => {
/** 获取生成设置好的文件名 */
var filename = res.headers["content-disposition"];
filename = filename.split("=")[1];
// 我看好多博客此处没有再次编码,我这里不重新编码,文件名称总是乱码
filename = escape(filename);
filename = decodeURIComponent(filename, "utf-8");
console.log(filename);
/** 接收文件流 */
const blob = new Blob([res.data]);
let url = URL.createObjectURL(blob);
/** 模拟浏览器操作Document,并模拟下载动作 */
let link = document.createElement("a");
link.style.display = "none";
link.href = url;
link.setAttribute("download", filename);
document.body.appendChild(link);
link.click();
});
},
本文来自博客园,作者:杯酒-故人,转载请注明原文链接:https://www.cnblogs.com/BeiJiuGuRen/p/16092481.html

浙公网安备 33010602011771号