openOutDia () {
let url = this.api + '接口地址'
let params = { //传参数
page_no: this.page,
page_size: this.pageSize,
shop_id: this.user.shopid,
start_time: this.time === '' ? this.defaultStart : this.time[0],
end_time: this.time === '' ? this.defaultEnd : this.time[1],
is_export: this.export
}
// responseType返回的文件流
this.$ajax.get(url, { params, responseType: 'blob' }).then((response) => { // 这里是声明期望返回的数据类型,为blob
const url = window.URL.createObjectURL(new Blob([response.data])) // 这里调用window的URL方法
const link = document.createElement('a') // 对象中创建一个对象,要与appendChild() 或 insertBefore()方法(在节点的子节点列表任意位置插入新的节点)联合使用
link.style.display = 'none' // 隐藏
link.href = url
link.setAttribute('download', '导出配方货品(成本与请货)记录.xls') //下载文档名称及后缀
document.body.appendChild(link) // 在节点的子节点列表末添加新的子节点
link.click() // 点击
document.body.removeChild(link) // 下载完成移除元素
window.URL.revokeObjectURL(url) // 释放掉blob对象
}).catch(err => {
this.tableData = []
this.loading = false
console.log(err)
})
},
导出EXCEL表格
于 2023-04-08 11:19:12 首次发布