前端涉及到導出文件時可以使用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')}