常用的工具函数


得到两个数组的并集, 两个数组的元素为数值或字符串
//tools.js
export const getUnion = (arr1, arr2) => {
  return Array.from(new Set([...arr1, ...arr2]))
}

//调用页面
import { getUnion } from '@/libs/tools'

this.getUnion  = getUnion([1,2,3,5],[1,4,6]) 
//(6) [1, 2, 3, 5, 4, 6]

// 示例 

this.openedNames = getUnion(this.openedNames, this.getOpenedNamesByActiveName(name)) 

// 回调函数
getOpenedNamesByActiveName (name) { 
   return this.$route.matched.map(item => item.name).filter(item => item !== name) 
}

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM