index.js 615 B

123456789101112131415161718192021222324252627
  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 为默认全局配置 */
  14. if (process.env.NODE_ENV === 'development') {
  15. defaultConfig.baseURL = '/api' /* 根域名 */
  16. }
  17. if (process.env.NODE_ENV === 'production') {
  18. defaultConfig.baseURL = '/api' /* 根域名 */
  19. }
  20. return defaultConfig
  21. })
  22. requestInterceptors()
  23. responseInterceptors()
  24. }
  25. export {
  26. initRequest
  27. }