本文主要是介绍vue-----window.open打开新窗口文件并且修改窗口标题下载文件,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
vue-----window.open打开新窗口文件并且修改窗口标题&&下载文件
// 下载word文件downloadFile(url, fileName) {const xhr = new XMLHttpRequest();xhr.open("GET", url, true);xhr.responseType = "blob";xhr.onload = function () {if (xhr.status === 200) {const blob = new Blob([xhr.response]);const a = document.createElement("a");const url = window.URL.createObjectURL(blob);a.href = url;a.download = fileName;a.click();window.URL.revokeObjectURL(url);}};xhr.send();},
openShowBtn(tag, url, fileName) {if (!url) return this.$message.error("文件为空!");if (tag === 2) { //打开新窗口const win = window.open("about:blank");win.document.title = fileName;const iframe = document.createElement("iframe");iframe.src = url;iframe.style.width = "100%";iframe.style.height = "100vh";iframe.style.margin = "0";iframe.style.padding = "0";iframe.style.overflow = "hidden";iframe.style.border = "none";win.document.body.style.margin = "0";win.document.body.appendChild(iframe);} else if (tag === 3) {//下载文件this.downloadFile(url, fileName);}},
这篇关于vue-----window.open打开新窗口文件并且修改窗口标题下载文件的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!