欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

导出excel,后端返回blob文件

程序员文章站 2024-03-20 22:10:52
...
	async down() {
			try {
				const params = {
					days: this.queryForm.date.join(','),
					appid: this.queryForm.appid.join(','),
					type: this.queryForm.type.join(','),
					adchannelid: this.queryForm.adchannelid.join(','),
					sdkVersion: this.queryForm.sdkVersion,
					versionName: this.queryForm.versionName,
					subadsenseid: this.queryForm.subadsenseid,
					page: this.pageable.pageNum,
					page_size: this.pageable.pageSize,
				}
				this.downLoading = true
				const res = await api.handleExportFunnel(params)
				this.downLoading = false
				const headers = res.headers['Content-Disposition'] || res.headers['content-disposition']
				const filename = headers.split('utf-8\'\'')[1]
				console.log(res.headers, '65465465465465')
				if (navigator.msSaveBlob) {
					// 兼容ie10+
					window.navigator.msSaveOrOpenBlob(res.data, filename)
					return false
				}
				// 其他主流浏览器
				let eleLink = document.createElement('a')
				eleLink.download = decodeURI(filename)
				eleLink.style.display = 'none'
				let blob = new window.Blob([res.data])
				eleLink.href = URL.createObjectURL(blob)
				document.body.appendChild(eleLink)
				eleLink.click()
				document.body.removeChild(eleLink)
			} finally {
				this.downLoading = false
			}
		},