function exportFun(url,params,type,fileName) {
// console.log(this)
this.$http.myPostJson(url,params).then(res => {
let blob = new Blob([res], {type: type})
let downloadElement = document.createElement('a')
let href = window.URL.createObjectURL(blob); //创建下载的链接
downloadElement.href = href;
// let fileName = ''
// for(let item in params){
// if(!params[item] || Object.prototype.toString.call(params[item]) == '[object Array]') break
// fileName += params[item] + '-'
// }
// fileName += 'Product Summary'
fileName = fileName
downloadElement.download = fileName; //下载后文件名
document.body.appendChild(downloadElement);
downloadElement.click(); //点击下载
document.body.removeChild(downloadElement); //下载完成移除元素
window.URL.revokeObjectURL(href); //释放blob对象
})
}
调用
let params = {
pageIndex: this.pageIndex,
pageSize: this.pageSize,
sortList: this.sortList,
param: this.formData
};
const type='text/csv'
this.$exportFun(this.$api.productTransExportUrl,params,type,'Product Trans')
Blob 下载文件时 type 类型 大全
https://blog.csdn.net/yin_you_yu/article/details/116261304