1. 封装的接口api方法
exportCoil(responseType:any) {
return REST.request(HTTPMethod.GET, `${this.url}/ExportCoilData`,responseType)
}
2. 组件中调用
exportExcel() {
this.coilAPI?.exportCoil('blob').then((res: any) => {
var blob = new Blob([res.data], {
type: "application/x-msdownload;charset=UTF-8"
})
let url = window.URL.createObjectURL(blob)
let link = document.createElement('a')
link.style.display = 'none'
link.href = url
link.id = 'Adownload'
//命名可能会出现问题,格式一定和后端下载的格式一样
link.setAttribute('download', `铝卷数据_ ${AiDateTime.YMD(new Date())}.xlsx`)
document.body.appendChild(link)
link.click()
})
}