/**
*
* @param obj 被过滤的对象
* @param keys 需要过滤的属性数组
* @returns
*/
export const filterData = (obj, keys) => {
return Object.keys(obj).reduce((newData, key) => {
if (!keys.includes(key)) {
newData[key] = obj[key]
}
return newData
}, {})
}
使用:
//原对象
this.defectDictInfo = {
id:'1',
code:2,
name:'name',
type:3
}
this.defectDictInfo = this.filterData(this.defectDictInfo, ['id', 'type']) //过滤多个或单个属性
//过滤后
// this.defectDictInfo = {
// code:2,
// name:'name',
// }