Przeglądaj źródła

优化:request传参data时过滤null值

萤火科技 1 rok temu
rodzic
commit
bfdf12b437
2 zmienionych plików z 7 dodań i 2 usunięć
  1. 1 1
      pages/checkout/index.vue
  2. 6 1
      utils/request/index.js

+ 1 - 1
pages/checkout/index.vue

@@ -370,7 +370,7 @@
         this.getOrderData()
         this.getOrderData()
       },
       },
 
 
-      // 显示积分说明
+      // 显示积分抵扣说明
       handleShowPoints() {
       handleShowPoints() {
         this.showPoints = true
         this.showPoints = true
       },
       },

+ 6 - 1
utils/request/index.js

@@ -2,6 +2,7 @@
  * request插件地址:https://ext.dcloud.net.cn/plugin?id=822
  * request插件地址:https://ext.dcloud.net.cn/plugin?id=822
  */
  */
 import store from '@/store'
 import store from '@/store'
+import { hasOwnProperty, isEmptyObject, filterNull } from '@/utils/util'
 import request from './request'
 import request from './request'
 import Config from '@/core/config'
 import Config from '@/core/config'
 
 
@@ -18,7 +19,7 @@ const $http = new request({
   defaultUploadUrl: 'upload/image',
   defaultUploadUrl: 'upload/image',
   // 设置请求头(如果使用报错跨域问题,可能是content-type请求类型和后台那边设置的不一致)
   // 设置请求头(如果使用报错跨域问题,可能是content-type请求类型和后台那边设置的不一致)
   header: {
   header: {
-    'content-type': 'application/json;charset=utf-8'
+    'Content-Type': 'application/json;charset=utf-8'
   },
   },
   // 请求超时时间, 单位ms(默认15000)
   // 请求超时时间, 单位ms(默认15000)
   timeout: 15000,
   timeout: 15000,
@@ -71,6 +72,10 @@ $http.requestStart = options => {
   // #ifdef H5
   // #ifdef H5
   options.header['domain'] = window.location.hostname
   options.header['domain'] = window.location.hostname
   // #endif
   // #endif
+  // 剔除data中为null的属性 (解决传参字符串'null'的问题)
+  if (hasOwnProperty(options, 'data') && !isEmptyObject(options.data)) {
+    options.data = filterNull(options.data)
+  }
   // return false 表示请求拦截,不会继续请求
   // return false 表示请求拦截,不会继续请求
   return options
   return options
 }
 }