salary-management-front/pc4mobx/hrmSalary/util/request.js

33 lines
1012 B
JavaScript

export const formHeaderPost = (url, method, params, header) => {
url = url + "?__random__=" + (new Date()).valueOf();
let formdata = new URLSearchParams();
Object.keys(params).map(key => {
formdata.append(key, params[key]);
});
return fetch(url, {
method, mode: "cors",
headers: { "Content-Type": "application/x-www-form-urlencoded", ...header },
body: formdata
}).then(res => res.json());
};
export const postFetch = (url, params) => {
url = url + "?__random__=" + (new Date()).valueOf();
return fetch(url, {
method: "POST",
mode: "cors",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(params)
}).then(res => res.json());
};
export const headerRequestFetch = (url, method, params, header) => {
url = url + "?__random__=" + (new Date()).valueOf();
return fetch(url, {
method, mode: "cors",
headers: { "Content-Type": "application/json", ...header },
body: JSON.stringify(params)
}).then(res => res.json());
};