const baseUrl = "https://xxxxxx.xxxxxx.cn";
function fetchHttp(parameters) {
parameters.method = parameters.method.toUpperCase();
parameters.url = baseUrl + parameters.url;
return fetch(parameters.url, {
body: parameters.data,
headers: {
"user-agent": "Mozilla/4.0 MDN Example",
"content-type": "application/json",
token: "8fc1f353-a677-4051-8cb9-25fb83b2a43a"
},
method: parameters.method
}).then((res) => res.json());
}
//调用
// fetchHttp({ method, url, data })
// .then((res) => console.log(res))
// .catch((error) => console.error(error));
fetch 封装
最新推荐文章于 2023-12-01 16:57:55 发布