post方式下载excel表格
request({
method: 'post',
url: this.exportUrl,
data: data,
responseType: 'blob' // 服务器返回的数据类型
}).then((res) => {
const blob = new Blob([res], { type: 'application/force-download' }) // Blob 对象表示一个不可变、原始数据的类文件对象
const fileReader = new FileReader() // FileReader 对象允许Web应用程序异步读取存储在用户计算机上的文件的内容
fileReader.readAsDataURL(blob)
// 开始读取指定的Blob中的内容。一旦完成,result属性中将包含一个data: URL格式的Base64字符串以表示所读取文件的内容
fileReader.onload = (e) => {
const a = document.createElement('a')
a.download = `表格.xls`
a.href = e.target.result
document.body.appendChild(a)
a.click()
document.body.removeChild(a)
}
}).catch(err => {
console.log(err)
})