常用的工具函數


得到兩個數組的並集, 兩個數組的元素為數值或字符串
//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