methods中写好去重的方法
newArrFn (arr) {
// .new Set方法,返回是一个类数组,需要结合 ...运算符,转成真实数组
return ([...new Set(arr)])
}
调用方法
data(){
newList:[]
},
假如 res.List 是 [{name:"a",branchId:"1"},
{name:"b",branchId:"2"},
{name:"c",branchId:"1"},
{name:"a",branchId:"3"}
]
res.List.forEach(item=>{
this.newList.push(item.branchId)
})
console.log("newList是",this.newArrFn(this.newList));
打印出来是 ["1","2","3"]