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) => {
//上传成功||失败
});
网友评论