import axios from 'axios';
import qs from 'qs';
let base = 'http://xxx.com';//域名
//封装
//防止头部被串改:
const axiosP = axios.create({
headers: { 'content-type': 'application/x-www-form-urlencoded' }
});
export const httpGet = (url, data) => {
return new Promise((resolve, reject) => {
axiosP.get(base + url,{params:data})
.then(res => {
console.log(1, res)
resolve(() => {
if (res.data.code == 200) {
return res.data;
} else {
console.log(res);
alert(res.data.msg);
}
});
})
.catch(err => {
reject(
console.log(err, '网络错误,get请求失败'),
alert('网络错误,get请求失败')
axios的 post 和 get 的简单封装
最新推荐文章于 2024-07-03 08:00:00 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)