Vue数组对象深拷贝

Vue数组对象深拷贝

导语:

1.一个数组A,A中有多个对象,将A复制为B,即B=A,此时如果对A中的对象值修改,B会跟随同时更改。
2.如果在Vue里不想这种双向绑定,选择深拷贝。
3.深拷贝的思想是用Object.assign(target,source)产生新的copy对象。

方法调用

function coppyArray(arr){
   return arr.map((e)=>{
        if(typeof e==='object'){
           return Object.assign({},e);
         }else{
           return e;
       }
     }) 
 }

猜你喜欢

转载自blog.csdn.net/qq_32340877/article/details/80007591
今日推荐