let _this = this;
if (res.data.type === "application/json") {
var blob = new Blob([res.data], {
type: "application/vnd.ms-excel",
});
var reader = new FileReader();
reader.readAsText(blob, "utf-8");
reader.onload = function (e) {
console.log(reader);
let resultObj = JSON.parse(reader.result);
console.log(resultObj);
if (resultObj.code !== 0) {
_this.$message({ message: resultObj.msg, type: "error" });
}
};
} else {
if (window.navigator.msSaveOrOpenBlob) {
// IE
try {
var blobObject = new Blob([encodeURI(res.data)]);
window.navigator.msSaveOrOpenBlob(blobObject, fileName);
} catch (e) {
console.log(e);
}
} else {
// console.log(res);
var blob = new Blob([res.data], {
type: "application/octet-stream;charset=UTF-8",
});
var downloadElement = document.createElement("a");
downloadElement.download = `信息.xls`;
downloadElement.href = window.URL.createObjectURL(blob); // 创建下载的链接
// console.log(downloadElement.href);
downloadElement.click(); // 点击下载
document.body.appendChild(downloadElement);
document.body.removeChild(downloadElement); // 下载完成移除元素
window.URL.revokeObjectURL(downloadElement.href); // 释放掉blob对象
}
}
vue下载excel文件 ,如何提示后端返回的错误信息
最新推荐文章于 2023-12-27 17:28:39 发布