async inspectionResultBinDingData(data, errorMessageMode = 'Notice') {
const response = await ajax.request({
responseType: 'blob',
errorMessageMode,
url: `/api/SI/inspectionRecordExport/inspectionResultBinDingData`,
method: 'post',
data: data
})
var blob = new Blob([response.data])
var downloadElement = document.createElement('a')
var href = window.URL.createObjectURL(blob) // 创建下载的链接
downloadElement.href = href
downloadElement.download = decodeURIComponent(
response.headers['content-disposition'].match(/filename\*=UTF-8''(.*)$/)[1]
)
document.body.appendChild(downloadElement)
downloadElement.click()
document.body.removeChild(downloadElement)
window.URL.revokeObjectURL(href)
}
前端处理后台返回的json 文件下载
最新推荐文章于 2025-02-24 11:35:27 发布
该段代码实现了一个异步函数,用于从服务器请求数据并将其转换为Blob对象。通过设置errorMessageMode,它能够处理错误通知方式。然后,利用创建的a元素模拟点击下载,文件名由响应头中的'content-disposition'字段提供。整个过程涉及Ajax请求、Blob对象创建及文件下载。
2719

被折叠的 条评论
为什么被折叠?



