根据搜索input框内容,粗略匹配数据显示

显示的数据 filterList 写在计算属性当中 只要数据发生变化,就会引起数据的变化

filterList () {
      var arr = []  //arr就是要循环显示的数据
      for (let tmp of this.leftList) {
          arr.push(tmp)
      }
      //不进行实时更新,只有按下button按钮时候才进行匹配  
      //所以 将input框里的内容重新赋值给一个变量
      //( this.selectInputChange = this.selectInput 输入框内容)
      if (this.selectInputChange.trim() !== '') {
        arr = []
        for (let i = 0; i < this.leftList.length; i++) {
          const inputCont = this.selectInputChange.trim().toUpperCase()
          const listCount = this.leftList[i].id
          if (listCount.indexOf(inputCont) > -1) {
            arr.push(this.leftList[i])
          }
        }
        this.selectInputChange = ''  // 会影响第二次的内容输入内容更新
        return arr
      }

      return arr
    },
发布了24 篇原创文章 · 获赞 2 · 访问量 9175

猜你喜欢

转载自blog.csdn.net/sunmeng_sunmeng/article/details/103988559