首先第一个a标签 , 类似于这样的
<a href="xxx.txt" download="xxx.txt" />
导出按钮的代码
// 导出
async batch() {
const res = await sendCardLogExport(this.search) // 接口及所需参数
const blob = new Blob([res], { type: res.type }) // 将文件流转换成blob
const downloadElement = document.createElement('a')
const href = window.URL.createObjectURL(blob)
downloadElement.href = href
document.body.appendChild(downloadElement)
downloadElement.click() // 通过点击事件 触发a标签
document.body.removeChild(downloadElement)// 移除元素;防止连续点击创建多个a标签
window.URL.revokeObjectURL(href)
}
让我看看返回的res是什么
点击导出之后是这样的
就可以直接下载了
可以直接复制粘贴使用 , 换个接口跟参数就好了