let params = {
compStartTm: Date.parse(this.searchForm.compStartTm) / 1000,
compEndTm: Date.parse(this.searchForm.compEndTm) / 1000 + 86400,
collectWay: this.searchForm.collectWay,
};
this.loading = true;
var _this = this;
this.$httpExt().post("/xxxx/xxxxxx", params, { responseType: 'arraybuffer' }).then(res => {
if (res) {
_this.loading = false;
const aLink = document.createElement("a");
let blob = new Blob([res.data], {type: "application/vnd.ms-excel"})
aLink.href = URL.createObjectURL(blob)
aLink.setAttribute('download', '哈哈哈哈' + '.xlsx') // 设置下载文件名称
aLink.click()
this.$refs.loadElement.appendChild(aLink)
}
},res => {
_this.$message.error(res.msg);
_this.loading = false;
});
这段代码展示了如何在Vue应用中生成一个Excel文件并提供下载。通过将日期转换为Unix时间戳,设置收集方式,然后利用HTTP post请求,将响应类型设置为arraybuffer,创建一个Blob对象,并设置下载链接实现文件下载。
4417

被折叠的 条评论
为什么被折叠?



