使用aixos实现文件下载
直接使用this.$axios.post(url,args)不能下载文件
解决方案:
- 安装
npm install js-file-download --save
- 全局注册
import fileDownload from "js-file-download";
Vue.prototype.$fileDownload = fileDownload;
- 使用
this.$axios.post("/download",this.$qs.stringify({fid:this.fids[i].fid}),{responseType:"arraybuffer"})
.then(res =>{
//第二个参数为文件名
this.$fileDownload(res.data,this.fids[i].fileName);
})
.catch(error =>{
this.$message.error("下载失败");
})