vue axios进行文件下载
使用js-file-download
- 安装js-file-download
npm install js-file-download --save
- 在main.js中进行全局注册
import fileDownload from "js-file-download";
Vue.prototype.$fileDownload = fileDownload;
- 使用
downloadFile(fid,fileName){
this.$axios.post("/download",this.$qs.stringify({fid:fid}),{responseType:"arraybuffer"})
.then(res =>{
this.$fileDownload(res.data,fileName);
})
.catch(error =>{
this.$message.error("下载失败");
})
}