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