var nObj = Object.assign({},obj,obj1);//花括号叫目标对象,后面的obj、obj1是源对象。对象合并是指:将源对象里面的属性添加到目标对象中去,若两者的属性名有冲突,后面的将会覆盖前面的
过滤项思路
selectFilter(k, o){
//先复制对象,修改复制的对象,在赋值回去
const {... obj} = this.search.filter;
if(k === 'cid3' || k === 'brandId'){
obj[k] = o.id;
}else
obj[k] = o;
this.search.filter = obj;
}
对象的查找(从数组中)
findValue(k,v){
if(!this.filters){
return;
}
if(k !=='brandId') return v;
//找到后返回filter
return this.filters.find(f=>f.k==='brandId').opts[0].name;
},
deleteFilter(k){
const {...obj} = this.search.filter;
//从数组中删除对象的属性
delete obj[k];
this.search.filter = obj;
}
computed : {
remainFilter(){
//获取所选则的key
const keys = Object.keys(this.search.filter);
return this.filters.filter(f => !keys.includes(f.key)&&f.opts.length > 1);
}
}