crootfast
Version:
大前端工程化命令行脚手架
31 lines (26 loc) • 784 B
JavaScript
import axios from "axios";
// 封装Ajax请求
const request = (method, url, data) => {
const config = {
method,
url
};
if (method === "get") {
config.params = data;
} else {
config.data = data;
}
return axios(config)
.then((response) => response || {})
.catch((error) => {
throw error;
});
};
export const get = (url, params, other) => {
return request("get", url, params, other);
};
export const post = (url, params, other) => request("post", url, params, other);
export const patch = (url, params, other) => request("patch", url, params, other);
export const put = (url, params, other) => request("put", url, params, other);
export const del = (url, params, other) => request("delete", url, params, other);
export default axios;