1. 程式人生 > >VUE前端如何實現Excel表格的導入導出?

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

tom tostring ie10 append get file none client win

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; } },

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