index.js 978 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // 引入拦截器配置
  2. import {
  3. requestInterceptors,
  4. responseInterceptors
  5. } from './interceptors.js'
  6. // 引入luch-request
  7. import {
  8. http
  9. } from '@/uni_modules/uview-plus'
  10. // 初始化请求配置
  11. const initRequest = (vm) => {
  12. http.setConfig((defaultConfig) => {
  13. // defaultConfig.baseURL = 'http://tkhtest.natapp1.cc' /* 根域名 */
  14. defaultConfig.baseURL = 'http://127.0.0.1' /* 根域名 */
  15. defaultConfig = {
  16. ...defaultConfig,
  17. custom: {
  18. loading: true, //是否显示loading
  19. isCloseLoad: true, //请求返回数据后,是否关闭loading
  20. validateCode: true,//验证code
  21. },
  22. }
  23. /* defaultConfig 为默认全局配置 */
  24. // if (process.env.NODE_ENV === 'development') {
  25. // defaultConfig.baseURL = '/api' /* 根域名 */
  26. // }
  27. // if (process.env.NODE_ENV === 'production') {
  28. // defaultConfig.baseURL = '/api' /* 根域名 */
  29. // }
  30. return defaultConfig
  31. })
  32. requestInterceptors()
  33. responseInterceptors()
  34. }
  35. export {
  36. initRequest
  37. }