得到两个数组的并集, 两个数组的元素为数值或字符串
//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)
}