Commit 4418eccfab178bbca5cf54ca74692598f19f5a6e

Authored by Cherelle Spencer
Committed by GitHub
1 parent 02d41197

fix(deepMerge): 修复递归合并操作, 合并数组未去重的bug (#2667)

Co-authored-by: 苗大 <caoshengmiao@hypergryph.com>
Showing 1 changed file with 3 additions and 2 deletions
src/utils/index.ts
... ... @@ -3,7 +3,7 @@ import type { App, Component } from &#39;vue&#39;;
3 3  
4 4 import { unref } from 'vue';
5 5 import { isArray, isObject } from '/@/utils/is';
6   -import { cloneDeep, mergeWith } from 'lodash-es';
  6 +import { cloneDeep, isEqual, mergeWith, unionWith } from 'lodash-es';
7 7  
8 8 export const noop = () => {};
9 9  
... ... @@ -48,7 +48,8 @@ export function deepMerge&lt;T extends object | null | undefined, U extends object
48 48 return mergeWith(cloneDeep(target), source, (objValue, srcValue) => {
49 49 if (isObject(objValue) && isObject(srcValue)) {
50 50 return mergeWith(cloneDeep(objValue), srcValue, (prevValue, nextValue) => {
51   - return isArray(prevValue) ? prevValue.concat(nextValue) : undefined;
  51 + // 如果是数组,合并数组(去重) If it is an array, merge the array (remove duplicates)
  52 + return isArray(prevValue) ? unionWith(prevValue, nextValue, isEqual) : undefined;
52 53 });
53 54 }
54 55 });
... ...