downLoadAccoutFile: function (url) {
var vm = this;
this.$axios({
url: url,
method: "post",
headers: {
"Content-Type": "application/json; application/octet-stream",
},
responseType: "blob",
})
.then(function (response) {
const blob = new Blob([response.data]);
const filename = response.headers["content-disposition"];
const downloadElement = document.createElement("a");
const href = window.URL.createObjectURL(blob); //创建下载的链接
downloadElement.href = href;
[downloadElement.download] = [
decodeURI(decodeURI(filename.split("=")[1])),
];
document.body.appendChild(downloadElement);
downloadElement.click(); //点击下载
document.body.removeChild(downloadElement); //下载完成移除元素
window.URL.revokeObjectURL(href); //释放blob对
})
.catch(function (error) {});
},
vue/js实现文件下载(blob) 格式
最新推荐文章于 2024-05-09 14:46:33 发布