vue模糊搜索

后端返回全部的数据,前端做一个模糊搜索。


js代码

 watch: {
    codeNum(val) {
      if (val.length > 0) {
        this.showClear = true;
        let result = [];
        this.bonds.map(item => {
          if (item.bondCode.indexOf(val) > -1) {
            result.push(item);
          }
        });
        this.bondsList = result;
      } else if (val.length == 0) {
        this.showClear = false;
        this.bondsList = this.bonds;    //this.bondList是后台请求的数据
      }
    }
  },

你可能感兴趣的:(Vue,vue,vue.js)