接口说明:
export function download (parameter) {
return axios({
url: '访问的接口',
method: 'get',
params: parameter, //参数
responseType: 'blob',
})
}
导出方法
//parameter 接口参数
download(parameter).then((res) => {
const link = document.createElement('a')
const blob = new Blob([res], { type: 'application/vnd.ms-excel' })
link.style.display = 'none'
link.href = URL.createObjectURL(blob)
link.download = 'name' // 下载的文件名
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
window.URL.revokeObjectURL(link.href) // 释放掉blob对象
}).catch(error => {
this.$message({
message: '下载失败!',
type: 'error'
})
})