in the vue project, you need to have an operation to export the table. The backend provides the interface to return the stream, and then the front end downloads
directly through the request. However, through the materials on the Internet, I have made it possible to download at present, but the size of the downloaded file is incorrect, and then the next file cannot be opened. The specific code is as follows:
//
download (data) {
if (!data) {
return
}
let url = window.URL.createObjectURL(new Blob([data]))
let link = document.createElement("a")
link.style.display = "none"
link.href = url
link.setAttribute("download", "excel.xlsx")
document.body.appendChild(link)
link.click()
},
//
exportReport() {
util.request.post({
url: "demand/analysis/file",
data: {
bg_code: this.businessGroup,
statistics_time: this.analysisData[this.selName+"time"]
},
that:this,
success: result=> {
this.download(result)
console.log(result)
},
fail: error=> {
console.log(error)
}
})
}
when the file is opened, it looks like this:
I tried it with postman"s send and download, and it works, but I just don"t know why this happens in my program. I hope the god who has encountered a similar situation can help guide me which part of my code has a problem