1.浅拷贝
es6 新增方法 Object.assign
const info = {name: "why", age: 18, friend: {name: "kobe"}};
const obj = Object.assign({}, info);
info.name = "kobe";
console.log(obj.name);
info.friend.name = "james";
console.log(obj.friend.name);
2.深拷贝
const info = {name: "why", age: 18, friend: {name: "kobe"}};
const obj = JSON.parse(JSON.stringify(info));
info.friend.name = "james";
console.log(obj.friend.name);
JSON.parse 用于将一个 Json 字符串转换成对象
JSON.stringify() 方法用于将 JavaScript 值转换为 JSON 字符串。
深拷贝
import _ from 'lodash';
let list = _.cloneDeep(this.user.followeds)