vue中使用文件流进行下载(new Blob),不打开一个新页面下载
exportfunctiondownload(url,params,filename){Message.warning('导出数据中')returnaxios.get(url,{params:params,responseType:'arraybuffer',}).then((r)=>{constcontent=r.dataconstblob=newBlob([content],{type:
·
export function download (url, params, filename) {
Message.warning('导出数据中')
return axios.get(url, {
params: params,
responseType:'arraybuffer',
}).then((r) => {
const content = r.data
const blob = new Blob([content],{type:'application/vnd.ms-excel'})
if ('download' in document.createElement('a')) {
const elink = document.createElement('a')
elink.download = filename
elink.style.display = 'none'
elink.href = URL.createObjectURL(blob)
document.body.appendChild(elink)
elink.click()
URL.revokeObjectURL(elink.href)
document.body.removeChild(elink)
Message.success('导出成功')
}
}).catch((r) => {
console.error(r)
Message.error('导出失败')
})
}
更多推荐
已为社区贡献30条内容
所有评论(0)