var da = {
'cs1': '参数1',
'cs2': '参数2',
}
// 响应格式决定了是否能接收到文件流,这里文件流设置的响应格式为arraybuffer
// withCredentials设置false,跨域请求
axios({
method: 'POST',
responseType: 'arraybuffer',
url: '接口地址',
withCredentials: false,
data: da
}).then(res => {
// res.data为接口所返回的文件流
// vnd.openxmlformats-officedocument.spreadsheetml.sheet表示设置下载格式为xlsx
// type是可变的,例如pdf的type为application/pdf等
var blob = new Blob([res.data], {
type: 'application/vnd.openxmlformats-
officedocument.spreadsheetml.sheet;chartset=UTF-8'
})
// 新窗口打开
var url = window.URL.createObjectURL(blob)
var a = document.createElement('a')
a.href = url
// 文件名
a.download = this.GetFileName()
a.click()
})