接口:类型(blob)
export function getDownload(params) {
return request({
url: '/weekly/api/submit/download',
method: 'get',
params,
responseType: 'blob'
})
}
页面调用的方法:
btnDownload() {
const fileId = this.fileId
getDownload({ fileId }).then((res) => {
console.log(res)
var blob = new Blob([res], {
type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document;charset=UTF-8'
})
// 解析格式( type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document;charset=UTF-8')
var filename = this.approverDetail.attachments.fileName
var a = document.createElement('a')
var url = window.URL.createObjectURL(blob)
a.href = url
a.download = filename
var body = document.getElementsByTagName('body')[0]
body.appendChild(a)
a.click()
body.removeChild(a)
window.URL.revokeObjectURL(url)
})
},
下载功能实现
猜你喜欢
转载自blog.csdn.net/qq_48294048/article/details/130382259
今日推荐
周排行