methods: {
exportDetail() {
let obj = {
name: '林同学',
remark: '接口返回流,前端导出文件'
}
downloadWord(obj).then((res) => {
// 处理返回的文件流
const blob = new Blob([res]);
const link = document.createElement("a");
link.download = "导出的文件名称";
link.style.display = "none";
link.href = URL.createObjectURL(blob);
document.body.appendChild(link);
link.click();
URL.revokeObjectURL(link.href);
document.body.removeChild(link);
ElMessage({
type: "success",
message: "导出成功",
});
});
},
}
// api文件
// 导出
export function downloadWord(data) {
return request({
url: `api/apiInfo/downloadWord`,
method: "post",
responseType: "blob", // 设置响应类型为blob
data,
});
}
后端返回文件流,vue导出
最新推荐文章于 2024-08-20 11:29:48 发布