You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
willaengine/resources/js/Global/utils/api/request/axiosApi.js

49 lines
854 B

import axios from "axios";
export default class axiosApi {
constructor(urlObj) {
this.staticMethods = ["get", "post", "put", "delete"];
this.baseURL = '/';
this.method = urlObj.method;
this.url = urlObj.url;
this.data = urlObj.data;
}
init() {
axios.defaults.baseURL = this.baseURL;
if (this.checkMethod()) {
return this[this.method]();
}
}
checkMethod() {
return this.staticMethods.includes(this.method);
}
get() {
const params = this.data;
return axios.get(this.url, {
params
});
}
post() {
return axios.post(this.url, this.data);
}
put() {
const data = this.data;
data['_method'] = 'put';
return axios.put(this.url, data);
}
delete() {
const data = this.data;
data['_method'] = 'delete';
return axios.put(this.url, data);
}
}