相信小伙伴们都写过数组过滤吧。在某一个列表上面,有一个input框,搜索列表中的某个值,来进行筛选。

我们可以利用数组的filter方法来实现。

注:

  • v_tableList: 列表需要的数据
  • v_filterKeyword: 搜索框双向绑定的key
  • v_detailList: 后台拿的数据
computed: {
    v_tableList () {
      if (this.v_filterKeyword !== '') {
        let keyword = this.v_filterKeyword.toLowerCase()
        return this.v_detailList.filter(item => {
          // 以name来搜索
          let str = item.name.toLowerCase()
          return str.indexOf(keyword) !== -1
        })
      } else {
        return this.v_detailList || []
      }
    }
  }

搞定~

Logo

前往低代码交流专区

更多推荐