response contentType applicationvndwordenableRangeProcessing falseentityTag nullfileContents UEsDBBQAAAAIAKFxf1bjgX0u8QAAANUCAAALAAAAX3JlbHMvLfileDownloadName 测试docxlastModified null这样的返回值在vue中使用blob接
在Vue中使用Blob接收该返回值的代码可以如下所示:
axios.get(url, { responseType: 'blob' })
.then(response => {
const blob = new Blob([response.data], { type: response.headers['content-type'] })
const downloadUrl = URL.createObjectURL(blob)
const link = document.createElement('a')
link.href = downloadUrl
link.download = response.data.fileDownloadName
link.click()
})
.catch(error => {
console.error(error)
})
这个代码片段使用了Axios来发送请求,并且在请求中设置了responseType为blob,以便接收二进制数据。在成功的回调函数中,我们将响应数据转换成Blob对象,然后使用URL.createObjectURL()方法创建一个下载链接,并将链接添加到DOM中去,最后通过link.click()方法触发点击下载的操作。
原文地址: https://www.cveoy.top/t/topic/54z 著作权归作者所有。请勿转载和采集!