59 lines
1.2 KiB
JavaScript
59 lines
1.2 KiB
JavaScript
const baseurl = "http://lottery.unipay.test.86698.cn/api"; // 测试
|
|
// const baseurl = ""; // 正式
|
|
//统一请求
|
|
axios.interceptors.request.use((config) => {
|
|
return config;
|
|
});
|
|
|
|
const req = {
|
|
//get请求
|
|
axiosGet(url, params) {
|
|
const obj = { method: "get", url: baseurl + url, params };
|
|
var result = axios(obj)
|
|
.then(function (res) {
|
|
return res.data;
|
|
})
|
|
.catch(function (error) {
|
|
return;
|
|
});
|
|
return result;
|
|
},
|
|
//post请求
|
|
axiosPost(url, data) {
|
|
let result = axios({
|
|
method: "post",
|
|
url: baseurl + url,
|
|
data: data,
|
|
header: {
|
|
"Content-type": "application/x-www-form-urlencoded"
|
|
}
|
|
})
|
|
.then((res) => {
|
|
return res.data;
|
|
})
|
|
.catch((error) => {
|
|
// return "exception=" + error
|
|
});
|
|
return result;
|
|
},
|
|
//put请求
|
|
axiosPut(url, data) {
|
|
let result = axios({
|
|
method: "put",
|
|
url: baseurl + url,
|
|
data: data,
|
|
header: {
|
|
"Content-type": "application/x-www-form-urlencoded"
|
|
}
|
|
})
|
|
.then((res) => {
|
|
return res.data;
|
|
})
|
|
.catch((error) => {
|
|
alert("服务器错误");
|
|
return "exception=" + error;
|
|
});
|
|
return result;
|
|
}
|
|
};
|