- this 在函数里面获取不到,所以要取出来
this.$api.getReliabilityReportWord(data).then((res) => {
const _this = this;
let fileReader = new FileReader();
fileReader.onload = function () {
try {
let jsonData = JSON.parse(this.result); // 说明是普通对象数据,后台转换失败
if (jsonData.code) {
console.log(jsonData, "jsonData");
_this.$message.error(jsonData.message);
}
} catch (err) {
// 解析成对象失败,说明是正常的文件流
let blob = new Blob([res]);
let downloadElement = document.createElement("a");
let href = window.URL.createObjectURL(blob);
downloadElement.href = href;
downloadElement.download = `可靠性文档计算书.docx`;
document.body.appendChild(downloadElement);
downloadElement.click();
document.body.removeChild(downloadElement);
window.URL.revokeObjectURL(href);
}
};
fileReader.readAsText(res);
});
标签:res,错误信息,jsonData,href,let,blob,downloadElement,后台
From: https://www.cnblogs.com/DL-CODER/p/16634983.html