vue项目中,axios接收后台返回的文档流xls数据,导出excel表格
// 事件函数
exportCase() { //点击后下载
if (this.checkArr.length > 0) {
// daochu 是这里封装的一个请求 自己写请求时一定要{responseType: 'blob'} 响应数据类型是必写的
daochu(qs.stringify({
heardNames: this.checkArr.join(","),
casIds: ID.join(",")
}), {responseType: 'blob'}).then(res => {
let url = window.URL.createObjectURL(new Blob([res], {type: 'application/x-xls'}))
let link = document.createElement('a')
link.style.display = 'none'
link.href = url
let timestamp = new Date().getTime()
let ran = Math.random()
link.setAttribute('download', "case_" + timestamp + "_" + ran + ".csv")
document.body.appendChild(link)
link.click()
window.URL.revokeObjectURL(url);//释放blob
})
} else {
this.$message.error('请选择表头');
}
本文地址:https://blog.csdn.net/qq_45919328/article/details/107511637
如对本文有疑问, 点击进行留言回复!!
vue 动态设置img的src地址无效,npm run build 后找不到文件的解决
解决vue动态路由异步加载import组件,加载不到module的问题
解决vue的router组件component在import时不能使用变量问题
Vue中的this.$options.data()和this.$data用法说明
GBase 8a MPP Cluster使用Ceph做存储计算分离
网友评论