Vue forEach 计算

Vue forEach in computed

我正在构建一个复选框过滤器,它将单击的复选框值存储在一个数组中。之后,计算数据应该会更新,但我总是不确定。

数据结构: 赌场{ brand_tags { Brand_Tag_Name } }

计算:

computed: {
    filteredCasinos: function() {
      return this.casinos.forEach(casino => {
        return casino.brand_tags.filter(brandTag => {
          return this.filteredCategories.includes(brandTag.Brand_Tag_Name)
        })
      })
    }
},

HTML(但我想这工作正常)

        <label for="Featured">Featured Casinos
          <input type="checkbox" v-model="filteredCategories" value="Featured">
        </label>
        <label for="Featured">Big Brands
          <input type="checkbox" v-model="filteredCategories" value="Big Brand">
        </label>
        <label for="Featured">New Casinos
          <input type="checkbox" v-model="filteredCategories" value="New Casino">
        </label>
        <label for="Featured">Pay n Play
          <input type="checkbox" v-model="filteredCategories" value="Pay N Play">
        </label>
        <label for="Featured">Trusted Casinos
          <input type="checkbox" v-model="filteredCategories" value="Trusted Casino">
        </label>

这是因为 return this.casinos.forEach returns 未定义。

{ filteredCasinos: function() {
return this.casinos.filter(casino => {
 return !!casino.brand_tags.find(brandTag => {
    return this.filteredCategories.includes(brandTag.Brand_Tag_Name)
    })
  })
}