1、在utils/request中写入公共方法
import axios from "axios";
const instance = axios.create({
timeout: 1000 * 60,
headers: {
post: {
"Content-Type": "application/json",
},
},
});
export const sendDefReq = async (method, option) => {
const defaultOption = {};
const res = instance({ method: "post", ...option });
return res;
};
2、 在fxtrData写公共接口
import { sendDefReq } from '@/utils/request'
export const exportExcel = (method, option) => sendDefReq(method, option)
使用
<script>
import {
exportExcel,
} from "@/api/fxtrData";
export default {
data() {
return {
};
},
methods: {
handleExport() {
exportExcel("post", {
url: "/business/seSoilInfoStatistics/export/exportExcel",
method: "post",
headers: {
Authorization: getStore(TOKEN_NAME),
"Content-Type": "application/json",
},
data: data,
responseType: "blob",
})
.then((res) => {
const blob = new Blob([res.data], { type: "text/plain" });
let filename = window.decodeURI(
res.headers["content-disposition"].split("=")[1]
);
const elink = document.createElement("a");
elink.download = filename;
elink.style.display = "none";
elink.href = URL.createObjectURL(blob);
document.body.appendChild(elink);
elink.click();
URL.revokeObjectURL(elink.href);
document.body.removeChild(elink);
})
.finally(() => {
});
},
},
};
</script>