import axios from 'axios';
const get = (path,data={},headers={})=>{
data.t = new Date().getTime();
let url = "http://localhost:8080" + path;
return new Promise(function(resolve,reject){
axios({
method: 'get',
url: url,
params: data,
headers:headers
}).then(resp=>{
resolve(resp.data || {});
}).catch(e=>{
reject(e);
});
});
};
const post = (path,data={},headers={"Content-Type":"application/json"})=>{
data.t = new Date().getTime();
let url = "http://localhost:8080" + path;
return new Promise(function(resolve,reject){
axios({
method: 'post',
url: url,
data: data,
headers:headers
}).then(resp=>{
resolve(resp.data || {});
}).catch(e=>{
reject(e);
});
});
};
export default {
get,
post,
};
axios网络请求封装
最新推荐文章于 2023-03-10 17:50:44 发布