认定了 就要好好的珍惜对待,人生不容辜负,你必须要更加努力 。加油 骚年。
vue 下载 xlsx文件 这里介绍两种 一种是命名文件夹再下载 一种是不命名随机名称下载
axios({
method: "GET",
url:"url地址"
params: data,
responseType: "blob",
})
.then((res) => {
console.log(res);
const blob = new Blob([res.data], {
type: "application/vnd.ms-excel",
});
//不命名下载
const url = window.URL.createObjectURL(blob);
window.location.href = url;
//命名下载
const link = document.createElement("a"); // 创建元素
let blob = new Blob([res.data], { type: "application/vnd.ms-excel" });
link.style.display = "none";
link.href = URL.createObjectURL(blob); // 创建下载的链接
link.setAttribute("download", "试算平衡表.xlsx"); // 给下载后的文件命名
document.body.appendChild(link);
link.click(); // 点击下载
document.body.removeChild(link); // 下载完成移除元素
window.URL.revokeObjectURL(link.href); // 释放掉blob对象
})
.catch((err) => {
console.log(err);
});
这里注意 一定要将 responseType 设置成 blob 才可以
如有不足之处请指出来 或联系邮箱 yuyong1663519276@163.com 谢谢