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