this.$http
.post(
"report/download",
{
name: this.name,
html: imageWrapper.innerHTML,
},
{
headers: {
"Content-Type": "application/json;charset=utf-8",
//"Content-Type": "application/x-www-form-urlencoded",
},
responseType: "blob", //关键
}
)
.then((res) => {
const pdfUrl = window.URL.createObjectURL(
new Blob([res.data], { type: `application/pdf` })
);
const link = document.createElement("a");
link.href = pdfUrl;
link.setAttribute("download", this.name);
document.body.appendChild(link);
link.click();
link.remove(); // 一次性的,用完就删除a标签
});