vue3+es6语法
直接上代码文章来源:https://www.toymoban.com/news/detail-574134.html
const objA = { name: '小飞', age: 18 };
const objACopy = { ...objA };
console.log('对比objA与objACopy的引用地址是否相同');
console.log(objA == objACopy); //false
console.log(objA);
console.log(objACopy);
//对象包含对象,浅拷贝
const objB = { name: '小飞', age: 18, hobbies: ['football', 'badminton'] };
const objBCopy = { ...objB };
console.log('对比objB与objBCopy的引用地址是否相同');
console.log(objB.hobbies == objBCopy.hobbies); //true
console.log(objB);
console.log(objBCopy);
//对象包含对象 改造一下,深拷贝
const objBCopyDeep = { ...objB, hobbies: { ...objB.hobbies } };
console.log(objB.hobbies == objBCopyDeep.hobbies); //false
文章来源地址https://www.toymoban.com/news/detail-574134.html
到了这里,关于vue对象复制(使用es6对象扩展运算符,深拷贝)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!