lodash 深拷贝 去重

import _ from 'lodash';

1.深拷贝

let arr1 = _.cloneDeep(arr2);

2.去重复, 保留的是 第一个参数和第二个参数的合集,根据第三个参数来去重

let arr1 = [

{name:'美在大连',nameEn:'11',type = 1}

{name:'学术论坛',nameEn:'11',type = 4}

]

let arr2= [

{name:'美在XX',nameEn:'the City',type = 1},

{name:'组织机构',nameEn:'22',type = 2},

]

let arr3 = _.unionBy(arr1, arr2, 'type')

// arr3 结果 为

[

{name:'美在大连',nameEn:'the City',type = 1},
{name:'学术论坛',nameEn:'11',type = 4}
{name:'组织机构',nameEn:'22',type = 2},

]

Demo code:

this.formData.modules = _.cloneDeep(_.unionBy(this.conferenceInfo?.modules || [], MODULE_TYPE, 'type')).filter((item) => !['99'].includes(item.type)).map((item) => ({
        type: item.type,
        name: item.name,
        nameEn: item.nameEn,
        isShow: item.isShow === '1',
        sort: item.sort,
        parentId:item.parentId
      }));

你可能感兴趣的:(插件,Vue,javascript)