axios封装get和post请求
时间: 2024-03-18 08:36:11 浏览: 82
axios 封装上传文件的请求方法
以下是axios封装get和post请求的例子:
1. 封装get请求
```javascript
export const get = (url, params) => {
return new Promise((resolve, reject) => {
axios.get(url, { params }).then(res => {
resolve(res.data);
}).catch(err => {
reject(err.data);
});
});
};
```
2. 封装post请求
```javascript
export const post = (url, params) => {
return new Promise((resolve, reject) => {
axios.post(url, QS.stringify(params)).then(res => {
resolve(res.data);
}).catch(err => {
reject(err.data);
});
});
};
```
阅读全文