直接看代码注释
import { message } from "antd";
import axios from "axios";
import qs from "qs";
let base = "https://www.baidu.com";
axios.defaults.withCredentials = false;
axios.defaults.timeout = 10000;
axios.interceptors.request.use(
config => {
return config;
},
err => {
message.error("请求超时");
return Promise.reject(err);
}
);
axios.interceptors.response.use(
response => {
return response ;
},
err => {
return Promise.reject(err);
}
);
export function myGet(url, params) {
let _url = base + url
return new Promise((resolve, reject) => {
axios.get(_url, {params}).then(function (response) {
resolve(response.data)
})
.catch(function (err) {
reject(err)
})
})
}
export function myPost(url, params) {
let _url = base + url
return new Promise((resolve, reject) => {
axios.post(_url, qs.stringify(params)).then(function (response) {
resolve(response.data)
})
.catch(function (err) {
reject(err)
})
})
}