可在手机浏览器下载文件的方法
后端获取的数据为blob格式的,结合a标签。
axios({
method: "get",
url: "/api/xxxx",
params: { xxxx },
responseType: "blob"
}).then(res => {
if (window.navigator.msSaveOrOpenBlob) {
navigator.msSaveBlob(res.data, this.title);
} else {
const elink = document.createElement("a");
elink.download = this.title;
elink.style.display = "none";
elink.href = URL.createObjectURL(res.data);
document.body.appendChild(elink);
elink.click();
document.body.removeChild(elink);
}
});
可在手机浏览器下载文件的方法
后端获取的数据为blob格式的,结合a标签。
axios({
method: "get",
url: "/api/xxxx",
params: { xxxx },
responseType: "blob"
}).then(res => {
if (window.navigator.msSaveOrOpenBlob) {
navigator.msSaveBlob(res.data, this.title);
} else {
const elink = document.createElement("a");
elink.download = this.title;
elink.style.display = "none";
elink.href = URL.createObjectURL(res.data);
document.body.appendChild(elink);
elink.click();
document.body.removeChild(elink);
}
});