Commit 9c43c741316bfe864680fff3b67601748e4ae02e
Committed by
GitHub
1 parent
c516d392
Revert "fix(deepMerge): fix recursive merge data without removing duplicate bugs (#2831)" (#2844)
This reverts commit 7ca007ec. Co-authored-by: jinmao88 <50581550+jinmao88@users.noreply.github.com>
Showing
1 changed file
with
10 additions
and
1 deletions
src/utils/index.ts
1 | -import type { App, Component } from 'vue'; | ||
2 | import type { RouteLocationNormalized, RouteRecordNormalized } from 'vue-router'; | 1 | import type { RouteLocationNormalized, RouteRecordNormalized } from 'vue-router'; |
2 | +import type { App, Component } from 'vue'; | ||
3 | 3 | ||
4 | import { intersectionWith, isEqual, mergeWith, unionWith } from 'lodash-es'; | 4 | import { intersectionWith, isEqual, mergeWith, unionWith } from 'lodash-es'; |
5 | import { unref } from 'vue'; | 5 | import { unref } from 'vue'; |
@@ -52,6 +52,14 @@ export function deepMerge<T extends object | null | undefined, U extends object | @@ -52,6 +52,14 @@ export function deepMerge<T extends object | null | undefined, U extends object | ||
52 | target: U, | 52 | target: U, |
53 | mergeArrays: 'union' | 'intersection' | 'concat' | 'replace' = 'replace', | 53 | mergeArrays: 'union' | 'intersection' | 'concat' | 'replace' = 'replace', |
54 | ): T & U { | 54 | ): T & U { |
55 | + | ||
56 | + return mergeWith(cloneDeep(target), source, (objValue, srcValue) => { | ||
57 | + if (isObject(objValue) && isObject(srcValue)) { | ||
58 | + return mergeWith(cloneDeep(objValue), srcValue, (prevValue, nextValue) => { | ||
59 | + // 如果是数组,合并数组(去重) If it is an array, merge the array (remove duplicates) | ||
60 | + return isArray(prevValue) ? unionWith(prevValue, nextValue, isEqual) : undefined; | ||
61 | + }); | ||
62 | + | ||
55 | if (!target) { | 63 | if (!target) { |
56 | return source as T & U; | 64 | return source as T & U; |
57 | } | 65 | } |
@@ -70,6 +78,7 @@ export function deepMerge<T extends object | null | undefined, U extends object | @@ -70,6 +78,7 @@ export function deepMerge<T extends object | null | undefined, U extends object | ||
70 | return source as T & U; | 78 | return source as T & U; |
71 | default: | 79 | default: |
72 | throw new Error(`Unknown merge array strategy: ${mergeArrays}`); | 80 | throw new Error(`Unknown merge array strategy: ${mergeArrays}`); |
81 | + | ||
73 | } | 82 | } |
74 | } | 83 | } |
75 | if (isObject(target) && isObject(source)) { | 84 | if (isObject(target) && isObject(source)) { |