/*
使用方法
import { downLoad } from 'this文件'
downLoad(url,params,name)
参数说明:
url:下载地址
params: 请求参数
name: 文件名称
*/
import axios from 'axios'
const downLoad = function(url, params,name) {
// imcis/safe/cisSmRedflagMaterscrtempl/exportExcelByEvalType
axios({
url: 'api/' + url,// 根据需求自己改
method: 'post',// 根据需求自己改
headers: {
'Content-Type': 'application/json'
},
data: params,
responseType: 'blob'
}).then((res) => {
let url = window.URL.createObjectURL(new Blob([res.data]), {
type: 'application/vnd.ms-excel',
'charset': 'utf-8',
'content-type': 'application/octet-stream'
})
let link = document.createElement('a')
link.style.display = 'none'
link.href = url
link.setAttribute('download', name+'.xlsx')
document.body.appendChild(link)
link.click();
}, (err) => {
console.log(err)
})
}
export {downLoad}
vue做excel文件导出(后端给的是二进制流)
最新推荐文章于 2023-02-07 15:52:50 发布