// 下载api
export async function downloadWord(data) {
const res = await request.post('/double-reduce/report/downloadWord', data, {
FORM: true,
responseType: 'blob', // 表明返回服务器返回的数据类型 这里不写接受类型,文件格式乱码
});
return res;
}
调用下载接口
下载类型对应
xls: ‘application/vnd.ms-excel’,
xlsx: ‘application/vnd.openxmlformats-officedocument.spreadsheetml.sheet’,
doc: ‘application/msword’,
docx: ‘application/vnd.openxmlformats-officedocument.wordprocessingml.document’,
pdf: ‘application/pdf’
downloadWord(this.qnList).then(res => {
const link = document.createElement("a");
let blob = new Blob([res], { type: "application/msword;charset=utf-8" });
link.style.display = "none";
link.href = URL.createObjectURL(blob);
//如果想改成 .xlsx 后缀可以这么写:
// link.setAttribute('download', '下载.xlsx')
// link.download = 'xxxxx.doc'
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
// this.fullscreenLoading.close();
})