纯前端excel导出单个、多个excel列表方法封装、download跨域文件路径、文件流下载方法封装、

封装方法:
export function downloadFile(url, fileName) { // 跨域文件路径、下载到本地的文件名
var x = new XMLHttpRequest()
x.open(‘GET’, url, true)
x.responseType = ‘blob’
x.onload = function(e) {
var url = window.URL.createObjectURL(x.response)
var a = document.createElement(‘a’)
a.href = url
a.download = fileName
a.click()
}
x.send()
}
vue文件引入
import { downloadFile } from ‘@/utils/download_streamFile’
点击下载方法:
dowmLoadFile(item) {
window.loading()
getFileDownloadUrl(item.fileUrl).then(res => {
downloadFile(res.data, item.fileName)
window.loading(false)
}).catch(() => {
window.loading(false)
})
},
第二种文件流下载方法:
export function downloadBlob(url, req, filename) {
let myRea = req
if (process.env.NODE_ENV === ‘producti

猜你喜欢

转载自blog.csdn.net/qq_33573589/article/details/109307193