导出 || 下载,解析数据流,type设置
>>解析数据流
let param = {
data: this.searchForm.data
}
this.btnDisabled = true
getDownloadList(param).then((res) => {
console.log(res)// 后台返回的是数据流
const link = document.createElement('a')
// 解析数据流
let blob = new Blob([res.data], {type: 'application/vnd.ms-excel'}) // 导出的类型在这里设置 Excel Word......
link.style.display = 'none'
link.href = URL.createObjectURL(blob)
// 下载名字
let fileName = decodeURI(res.headers['content-disposition']).replace(/attachment;filename=/, '') // 这个地方也要注意一下
link.download = fileName
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
this.btnDisabled = false
}).catch(() => {
this.btnDisabled = false
})
>>导出type类型设置
'Excel' => 'application/vnd.ms-excel'
'doc' => 'application/msword',
'bin' => 'application/octet-stream',
'exe' => 'application/octet-stream',
'so' => 'application/octet-stream',
'dll' => 'application/octet-stream',
'pdf' => 'application/pdf',
'ai' => 'application/postscript',
'xls' => 'application/vnd.ms-excel',
'ppt' => 'application/vnd.ms-powerpoint',
'dir' => 'application/x-director',
'js' => 'application/x-javascript',
'swf' => 'application/x-shockwave-flash',
'xhtml' => 'application/xhtml+xml',
'xht' => 'application/xhtml+xml',
'zip' => 'application/zip',
'mid' => 'audio/midi',
'midi' => 'audio/midi',
'mp3' => 'audio/mpeg',
'rm' => 'audio/x-pn-realaudio',
'rpm' => 'audio/x-pn-realaudio-plugin',
'wav' => 'audio/x-wav',
'bmp' => 'image/bmp',
'gif' => 'image/gif',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
'png' => 'image/png',
'css' => 'text/css',
'html' => 'text/html',
'htm' => 'text/html',
'txt' => 'text/plain',
'xsl' => 'text/xml',
'xml' => 'text/xml',
'mpeg' => 'video/mpeg',
'mpg' => 'video/mpeg',
'avi' => 'video/x-msvideo',
'movie' => 'video/x-sgi-movie',