request.js 816 B

12345678910111213141516171819202122232425262728293031323334
  1. const { Axios } = require('axios');
  2. /**
  3. * 通用请求封装类
  4. */
  5. class Request {
  6. constructor(config) {
  7. this.instance = new Axios({
  8. baseURL: config.baseURL || '',
  9. timeout: 60000,
  10. timeoutErrorMessage: '请求超时',
  11. withCredentials: true,
  12. headers: {
  13. 'Content-Type': 'application/json',
  14. },
  15. });
  16. }
  17. get(url, config = {}) {
  18. return this.instance.get(url, config);
  19. }
  20. post(url, params, config = {}) {
  21. return this.instance.post(url, params, config);
  22. }
  23. put(url, params, config = {}) {
  24. return this.instance.put(url, params, config);
  25. }
  26. patch(url, params, config = {}) {
  27. return this.instance.patch(url, params, config);
  28. }
  29. delete(url, config = {}) {
  30. return this.instance.delete(url, config);
  31. }
  32. }
  33. module.exports = new Request({});