Vue 数组去重:如何避免 this.mustMiddlegroundDifArr 数组中数据重复
要避免'this.mustMiddlegroundDifArr'数组中的数据重复,可以在每次赋值之前先判断数据是否已经存在于数组中。以下是一个可能的解决方案:
// 在每次赋值之前先判断数据是否已经存在于数组中
this.mustMiddlegroundDifArr = this.mustMiddlegroundDifArr.concat(this.selectionRows.filter(row => !this.mustMiddlegroundDifArr.includes(row)));
这里使用了'filter'方法来过滤掉已经存在于'this.mustMiddlegroundDifArr'数组中的数据。然后使用'concat'方法将过滤后的数据与原数组合并,以实现去重效果。
原文地址: https://www.cveoy.top/t/topic/qlCe 著作权归作者所有。请勿转载和采集!