Cherelle Spencer
2023-04-04 4418eccfab178bbca5cf54ca74692598f19f5a6e
fix(deepMerge): 修复递归合并操作, 合并数组未去重的bug (#2667)

Co-authored-by: 苗大 <caoshengmiao@hypergryph.com>
1个文件已修改
5 ■■■■■ 已修改文件
src/utils/index.ts 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/utils/index.ts
@@ -3,7 +3,7 @@
import { unref } from 'vue';
import { isArray, isObject } from '/@/utils/is';
import { cloneDeep, mergeWith } from 'lodash-es';
import { cloneDeep, isEqual, mergeWith, unionWith } from 'lodash-es';
export const noop = () => {};
@@ -48,7 +48,8 @@
  return mergeWith(cloneDeep(target), source, (objValue, srcValue) => {
    if (isObject(objValue) && isObject(srcValue)) {
      return mergeWith(cloneDeep(objValue), srcValue, (prevValue, nextValue) => {
        return isArray(prevValue) ? prevValue.concat(nextValue) : undefined;
        // 如果是数组,合并数组(去重) If it is an array, merge the array (remove duplicates)
        return isArray(prevValue) ? unionWith(prevValue, nextValue, isEqual) : undefined;
      });
    }
  });