利用Blob下载文件

前端涉及到导出文件时可以使用Blob进行下载
这里是用的vue

this.$store.dispatch('exportList').then((response) => {        
var blob = new Blob([response], {type: 'application/vnd.ms-excel'})        
var downloadElement = document.createElement('a')        
var href = window.URL.createObjectURL(blob) // 创建下载的链接        
downloadElement.href = href        
document.body.appendChild(downloadElement)        
downloadElement.click() // 点击下载        
document.body.removeChild(downloadElement) // 下载完成移除元素  
window.URL.revokeObjectURL(href) // 释放掉blob对象      
}).catch(() => {
      })
`

请求接口时一定要用download方式

export function exportList() {  return http.download('/order/appeal/export')}
发布了167 篇原创文章 · 获赞 20 · 访问量 2万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章