调用导出 this.$http({ method: "POST", url: 'user/fileGeneration', responseType: "blob", //定义为blob data: {}, }).then((res) => { this.dialogVisible = false const file = new Blob([res.data]); const a = document.createElement("a"); const fileName = '调研记录列表.xlsx';//下载文件名称 a.download = fileName a.style.display = 'none' a.href = URL.createObjectURL(file); document.body.appendChild(a); a.click(); URL.revokeObjectURL(a.href); document.body.removeChild(a); })
截取数据流中的文件名
let temp = res.headers["content-disposition"].split(";")[1].split("filename=")[1]
let fileName = decodeURIComponent(temp)
a.download = fileName
下载本地的excel表格
先把excel放在public下面
this.dialogVisible = false const a = document.createElement('a'); a.href = '/reponse.xls'; a.download = 'reponse.xls'; console.log(a.href) a.style.display = 'none'; document.body.appendChild(a); a.click(); a.remove();