美文网首页
axios的上传与下载

axios的上传与下载

作者: LemonTree7 | 来源:发表于2019-06-21 09:49 被阅读0次

1、设置axios下载api

例如

const xxx = {
  exportFile: (params) => _axios.post("http: //xxxxxx/exportFile", params, {responseType:'blob'})
}

//下载的地方使用
import saveAs from "file-saver;

xxx.exportFile(params).then((res) => {
    saveAs(new Blob([res.data], {type: "application/vnd.ms-excel"}), `xxxxxx.xls`);
});

2、使用axios进行文件上传

const xxx = {
  uploadFile:  (params) => axios.post(`http: //xxxxxx/uploadFile`, params, {headers: {
    "Content-Type": "multipart/form-data"
  }})
}

//上传时使用
const form = new FormData();
form.append("labelDataFile", param.file);
form.append("data", param.data.data);
xxx .uploadFile(form).then((res) => {
  //上传成功||失败
});

相关文章

网友评论

      本文标题:axios的上传与下载

      本文链接:https://www.haomeiwen.com/subject/cnpeqctx.html