useDeepClone
Introduction
深拷贝对象
Basic Usage
ts
import { useDeepClone } from '@flypeng/tool/browser';
const targetObj = { name: '@flypeng-tool', address: { x: 100 }, origin: targetObj };
const resultObj = useDeepClone(targetObj);
Online Demo
useDeepClone
拷贝目标:@flypeng-tool 拷贝目标:100
结果目标:change-@flypeng-tool 结果目标:1000
<script lang="ts" setup>
import { useDeepClone } from '@flypeng/tool/browser';
let targetObj: {
name: string;
address: any;
origin: any;
} = { name: '@flypeng-tool', address: { x: 100 }, origin: undefined };
targetObj.origin = targetObj;
const resultObj = useDeepClone(targetObj);
resultObj.name = 'change-@flypeng-tool';
resultObj.address.x = 1000;
</script>
<template>
<div>拷贝目标:{{ targetObj.name }} 拷贝目标:{{ targetObj.address.x }}</div>
<div>结果目标:{{ resultObj.name }} 结果目标:{{ resultObj.address.x }}</div>
</template>
Type Declaration
ts
/**
* 深拷贝对象
* @param targetObj 目标对象
* @param hashMap
* @returns
*/
declare function useDeepClone(targetObj: any, hashMap?: WeakMap<object, any>): any;