首页 > 解决方案 > Vue在getter中链接多个过滤器

问题描述

在 Getter 上,我需要过滤一个数组并返回符合 2 个条件的值。我需要返回没有 item_category_location 等于当前位置或根本没有 item_category_locations 的 item_categories。

 unaddedItemCategories(state, getters, rootState) {
                let otherLocations = state.item_categories
                    .filter((item_category) =>
                        item_category.item_category_locations.some((item_category_location) => item_category_location.location_id !== rootState.currentLocation.id))
                let noLocations = state.item_categories
                    .filter(item_category => item_category.item_category_locations.length == 0)
                return otherLocations, noLocations

            },

2个过滤器工作正常。如何链接它们以创建新数组?

标签: vue.jsvuex

解决方案


你可以这样做:

return [...otherLocations, ...noLocations]

推荐阅读