12345678910111213141516171819202122232425262728293031323334 |
- const { Axios } = require('axios');
- /**
- * 通用请求封装类
- */
- class Request {
- constructor(config) {
- this.instance = new Axios({
- baseURL: config.baseURL || '',
- timeout: 60000,
- timeoutErrorMessage: '请求超时',
- withCredentials: true,
- headers: {
- 'Content-Type': 'application/json',
- },
- });
- }
- get(url, config = {}) {
- return this.instance.get(url, config);
- }
- post(url, params, config = {}) {
- return this.instance.post(url, params, config);
- }
- put(url, params, config = {}) {
- return this.instance.put(url, params, config);
- }
- patch(url, params, config = {}) {
- return this.instance.patch(url, params, config);
- }
- delete(url, config = {}) {
- return this.instance.delete(url, config);
- }
- }
- module.exports = new Request({});
|