vbenjs / vben3

Next-generation Vben framework
https://vben.mufei88.com/
MIT License
559 stars 152 forks source link

utils.ts 文件里面的额 deepMerge 是不是有问题,对函数无效 #339

Closed hlovingness closed 8 months ago

hlovingness commented 8 months ago

原先是这样,对函数参数无效,表现在自定义 createAxios,添加 transform 下的 transformRequestHook 钩子等

function deepMerge<T = any>(src: any = {}, target: any = {}): T {
  let key: string
  for (key in target) {
    src[key] =
      (isObject(src[key]) && src[key] !== null)
        ? deepMerge(src[key], target[key])
        : (src[key] = target[key])
  }
  return src
}

得改成这样

function deepMerge<T = any>(src: any = {}, target: any = {}): T {
  let key: string
  for (key in target) {
    src[key] =
      (isObject(src[key]) && src[key] !== null) && !isFunction(src[key])
        ? deepMerge(src[key], target[key])
        : (src[key] = target[key])
  }
  return src
}