Unipay-H5/dof-api.js

59 lines
1.1 KiB
JavaScript
Raw Normal View History

2024-08-06 18:47:06 +08:00
const baseurl = "http://192.168.110.50:8000"; // 本地
// const baseurl = "http://lottery.unipay.test.86698.cn/api"; // 测试
2024-06-04 12:00:02 +08:00
// const baseurl = "https://lottery.unipay.api.86698.cn"; // 正式
2024-05-31 10:45:11 +08:00
// 统一请求
// 返送之前
2024-05-29 10:42:31 +08:00
axios.interceptors.request.use((config) => {
2024-05-31 10:45:11 +08:00
config.headers = {
token: localStorage.getItem("yl_token")
? localStorage.getItem("yl_token")
: ""
};
2024-05-29 10:42:31 +08:00
return config;
});
2024-05-31 10:45:11 +08:00
// 发送之后
axios.interceptors.response.use(
(response) => {
// to do
return response.data;
},
(error) => {
// to do
return Promise.reject(error);
}
);
2024-05-29 10:42:31 +08:00
const req = {
//get请求
axiosGet(url, params) {
2024-05-31 10:45:11 +08:00
var result = axios({
method: "get",
2024-05-29 10:42:31 +08:00
url: baseurl + url,
2024-05-31 10:45:11 +08:00
params
2024-05-29 10:42:31 +08:00
})
.then((res) => {
2024-05-31 10:45:11 +08:00
return res;
2024-05-29 10:42:31 +08:00
})
.catch((error) => {
2024-05-31 10:45:11 +08:00
return new Error(error);
2024-05-29 10:42:31 +08:00
});
return result;
},
2024-05-31 10:45:11 +08:00
//post请求
axiosPost(url, data) {
2024-05-29 10:42:31 +08:00
let result = axios({
2024-05-31 10:45:11 +08:00
method: "post",
2024-05-29 10:42:31 +08:00
url: baseurl + url,
2024-05-31 10:45:11 +08:00
data: data
2024-05-29 10:42:31 +08:00
})
.then((res) => {
2024-05-31 10:45:11 +08:00
return res;
2024-05-29 10:42:31 +08:00
})
.catch((error) => {
2024-05-31 10:45:11 +08:00
return new Error(error);
2024-05-29 10:42:31 +08:00
});
return result;
}
};