mirror of
https://gitee.com/lyt-top/vue-next-admin
synced 2026-07-06 21:45:37 +08:00
22 lines
382 B
TypeScript
22 lines
382 B
TypeScript
/**
|
|
* 对象深克隆
|
|
* @param obj 源对象
|
|
* @returns 克隆后的对象
|
|
*/
|
|
export function deepClone(obj: any) {
|
|
let newObj: any;
|
|
try {
|
|
newObj = obj.push ? [] : {};
|
|
} catch (error) {
|
|
newObj = {};
|
|
}
|
|
for (let attr in obj) {
|
|
if (typeof obj[attr] === 'object') {
|
|
newObj[attr] = deepClone(obj[attr]);
|
|
} else {
|
|
newObj[attr] = obj[attr];
|
|
}
|
|
}
|
|
return newObj;
|
|
}
|