1、接口
const test = {
//get访问下载接口
getDownLoad: (params) => axios.get(url + "fileInfo/getDownLoad", {params: params, responseType: "blob"}),
//post访问下载接口
postDownLoad: (params) => axios.post(url + "fileInfo/postDownLoad", {}, {params: params, responseType: "blob"}),
};
2、使用file-saver下载文件
import {saveAs} from "file-saver";
const params = {
token: "defaultToken"
};
test.getDownLoad(params).then((res) => {
saveAs(new Blob([res.data], {type: res.data.type || "application/octet-binary"}), `测试下载.pdf`);
});
网友评论