down (val, pid) {
this.fileName=val//自己定义的文件名称
axios({
method: 'post',
url: myfun()+'/router/downLoad?routerId=' + val + '&routerPid=' + pid + '',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Authentication: store.state.account.token//我这块需要传递token
},
responseType: 'arraybuffer',//arraybuffer/blob//加上格式,二进制
}).then(res => {
console.log(res)
console.log(res.data)
const blob = new Blob([res.data], {type: 'application/zip;charset=utf-8'});
const fileName = this.fileName+'_config.ini'//下载的文件名称及其后缀,后缀要和后台保持的一致
if ('download' in document.createElement('a')) { // 非IE下载
const elink = document.createElement('a')
elink.download
axios获取后台返回的二进制流并下载下来
最新推荐文章于 2024-04-29 14:43:35 发布