2021-07-07 javascript 深度拷贝deep clone vue.js

javascript deepclone

参考https://stackoverflow.com/questions/122102/what-is-the-most-efficient-way-to-deep-clone-an-object-in-javascript 使用lodash - cloneDeep;

步骤如下:

1.安装外部库

npm i lodash.clonedeep

2.调用外部库,封装使用:

import lodashCloneDeep from 'lodash.clonedeep'
function deepCopy(data) {
  //深度拷贝数据
  return lodashCloneDeep(data)
}
const obj = {'a': 1, 'b': 2}
const obj2 = deepCopy(obj)
console.log(obj, obj2, obj === obj2);

你可能感兴趣的:(vue.js,js,javascript,深度拷贝)