注意:请求头加上responseType:‘blob’,否则可能会出现乱码问题
async exportExcel(){
if(this.ArrFid.length == 0) return this.$message.warning('请选择表格导出内容')
const res = await http.postHandleExport({ids:this.ArrFid})
var blob = new Blob([res], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8' })
var link = document.createElement('a')
var url = window.URL.createObjectURL(blob)
link.style.display = 'none'
link.href = url
link.download = '台账明细.xls'
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
window.URL.revokeObjectURL(url)
},
如果上面代码依旧有问题,则需用原生axios写法,具体如下:
axios.post('/bj-slfh/business/damage/exportExcel',{ids:this.ArrFid},{responseType: "blob"}).then(res => {
var blob = new Blob([res.data], {type: "application/vnd.ms-excel"})
var link = document.createElement('a')
var url = window.URL.createObjectURL(blob)
link.style.display = 'none'
link.href = url
link.download = '台账明细.xlsx'
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
window.URL.revokeObjectURL(url)
})