最近在看Vue_shop实战项目-电商管理系统(Element-UI)的B站视频,看到 P172 08.商品添加-把goods_cat从数组转换为字符串时,讲到了Lodash这个工具库的cloneDeep方法的使用。 Lodash是一个一致性、模块化、高性能的 JavaScript 实用工具库,其官网地址为:https://www.lodashjs.com/,Github托管地址为:https://github.com/lodash/lodash
<script src="lodash.js"></script>
$ npm i -g npm
$ npm i --save lodash
// Load the full build.
var _ = require('lodash');
// Load the core build.
var _ = require('lodash/core');
// Load the FP build for immutable auto-curried iteratee-first data-last methods.
var fp = require('lodash/fp');
// Load method categories.
var array = require('lodash/array');
var object = require('lodash/fp/object');
// Cherry-pick methods for smaller browserify/rollup/webpack bundles.
var at = require('lodash/at');
var curryN = require('lodash/fp/curryN');
Lodash 通过降低 array、number、objects、string 等等的使用难度从而让 JavaScript 变得更简单。 Lodash 的模块化方法 非常适用于:
Lodash 提供 多种构建方式 和模块格式。
lodash & per method packages lodash-es, babel-plugin-lodash, & lodash-webpack-plugin lodash/fp lodash-amd
futil-js 是一套用来补足 lodash 的实用工具集。
在 Chrome 74-75、Firefox 66-67、IE 11、Edge 18、Safari 11-12 和 Node.js 8-12 环境中测试通过。
_.cloneDeep(value)
这个方法类似_.clone,除了它会递归拷贝 value。(注:也叫深拷贝)。 添加版本 1.0.0
参数 value (): 要深拷贝的值。 返回 (): 返回拷贝后的值。 例子如下:
var objects = [{ 'a': 1 }, { 'b': 2 }];
var deep = _.cloneDeep(objects);
console.log(deep[0] === objects[0]);
// => false
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有