zhengnaiwen_citu 1 рік тому
батько
коміт
ab8722b1c3
4 змінених файлів з 54 додано та 0 видалено
  1. 0 0
      src/api/common/index.js
  2. 23 0
      src/config/axios/config.js
  3. 31 0
      src/config/axios/index.js
  4. 0 0
      src/utils/index.js

+ 0 - 0
src/api/common/index.js


+ 23 - 0
src/config/axios/config.js

@@ -0,0 +1,23 @@
+const config = {
+  /**
+   * api请求基础路径
+   */
+  base_url: import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL,
+  /**
+   * 接口成功返回状态码
+   */
+  result_code: 200,
+
+  /**
+   * 接口请求超时时间
+   */
+  request_timeout: 30000,
+
+  /**
+   * 默认接口请求类型
+   * 可选值:application/x-www-form-urlencoded multipart/form-data
+   */
+  default_headers: 'application/json'
+}
+
+export { config }

+ 31 - 0
src/config/axios/index.js

@@ -0,0 +1,31 @@
+import { service } from './service'
+
+import { config } from './config'
+
+const { default_headers } = config
+
+const request = (option) => {
+  const { url, method, params, data, headersType, responseType, ...config } = option
+  return service({
+    url: url,
+    method,
+    params,
+    data,
+    ...config,
+    responseType: responseType,
+    headers: {
+      'Content-Type': headersType || default_headers
+    }
+  })
+}
+export default {
+  get: async (url, params, headersType, responseType) => {
+    return request({
+      url: url,
+      method: 'get',
+      params: params,
+      headersType: headersType,
+      responseType: responseType
+    })
+  }
+}

+ 0 - 0
src/utils/index.js