VUE前端如何實現Excel表格的導入導出?


exportOpera(res, fileName, flag) {
const self = this;
let content;
let blob;
if (Object.prototype.toString.call(res) === "[object Function]") {
content = res();
const fr = new FileReader();
blob = new Blob([content]);
fr.readAsText(blob);
fr.onload = function (e) {
const responseJSON = JSON.parse(e.target.result);
self.exportSwitch(responseJSON.resultCode, flag);
};
} else {
content = res;
blob = new Blob([content]);
if ("download" in document.createElement("a")) {
// 非IE下載
const elink = document.createElement("a");
elink.download = fileName;
elink.style.display = "none";
elink.href = URL.createObjectURL(blob);
document.body.appendChild(elink);
elink.click();
URL.revokeObjectURL(elink.href); // 釋放URL 對象
document.body.removeChild(elink);
} else {
// IE10+下載
navigator.msSaveBlob(blob, fileName);
}
}
},
exportSwitch(resultCode, flag) {
if (flag === "exportLogData") {
resultCode === 10001 ?
this.alertNotify(false, {
text: "下載",
message: "系統異常"
}) :
this.redirectLogin();
}
},
redirectLogin() {
removeLocalStorage("smoke_session_token");
this.resetState();
this.$router.replace({
path: "/login",
query: {
redirect: this.$router.currentRoute.fullPath
}
});
this.$message.error("登錄已失效,請重新登錄!");
if (window.stompClient) {
window.stompClient.disconnect();
delete window.stompClient;
}
},


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM