Filter list with Vue.js

前端 未结 4 1799
我在风中等你
我在风中等你 2020-11-30 04:07

I just got started with Vue.js and here is what I\'m doing: I am rendering a list of products, and each product has a name, a gender and a si

4条回答
  •  北荒
    北荒 (楼主)
    2020-11-30 04:22

    computed: {
            filteredItems() {
              return this.allStartupData.filter(item => {
                let byName =
                  item.name.toLowerCase().indexOf(this.search.toLowerCase()) > -1;
                let byDescription =
                  item.description.toLowerCase().indexOf(this.search.toLowerCase()) >
                  -1;
                if (byName === true) {
                  return byName;
                } else if (byDescription === true) {
                  return byDescription;
                }
              });
            }
          }
    

    and then u can iterate through filteredItems like e.g

     
    

提交回复
热议问题