Commit df0e0cbe69b076b35c24c90125e2bb59816c5240

Authored by ludens blunt
Committed by GitHub
1 parent 7dcb38ca

Update index.ts (#2336)

fix(deepMerge): 原对象受浅拷贝影响的问题
Showing 1 changed file with 4 additions and 2 deletions
src/utils/index.ts
... ... @@ -3,6 +3,7 @@ import type { App, Plugin } from 'vue';
3 3  
4 4 import { unref } from 'vue';
5 5 import { isObject } from '/@/utils/is';
  6 +import { cloneDeep } from 'lodash-es';
6 7  
7 8 export const noop = () => {};
8 9  
... ... @@ -35,10 +36,11 @@ export function setObjToUrlParams(baseUrl: string, obj: any): string {
35 36 // 深度合并
36 37 export function deepMerge<T = any>(src: any = {}, target: any = {}): T {
37 38 let key: string;
  39 + const res: any = cloneDeep(src)
38 40 for (key in target) {
39   - src[key] = isObject(src[key]) ? deepMerge(src[key], target[key]) : (src[key] = target[key]);
  41 + res[key] = isObject(res[key]) ? deepMerge(res[key], target[key]) : (res[key] = target[key]);
40 42 }
41   - return src;
  43 + return res;
42 44 }
43 45  
44 46 export function openWindow(
... ...