vue使用之搜索下拉选择框内容需要获取

自己使用记录,有问题欢迎探讨。

适用于搜索栏的下拉选择框不是从字典取,而是通过后台从数据库中的某个表取值。

目前只是能够实现,具体意义还不太懂,以后会了随时补充。

1.搜索栏处代码

 <el-form-item label="工种" prop="gzId">
        <el-select v-model="queryParams.gzId"
                   @change="changeGzs" clearable
                   filterable
                   :filterMethod="gzFilter"
                   placeholder="请选择工种">
          <el-option
            v-for="item in gzsFilter"
            :key="item.gzId"
            :label="item.gzName"
            :value="item.gzId"
          ></el-option>
        </el-select>
      </el-form-item>

2.changeGzs 方法

changeGzs(data){
          this.queryParams.gzId=data;
        },

3.gzFilter 过滤器
    gzFilter(val) {
      this.gzQuery = val;
      if (val) { //val存在
        this.gzsFilter = this.gzs.filter((item) => {
          if (!!~item.gzName.indexOf(val) || !!~item.gzName.toUpperCase().indexOf(val.toUpperCase())) {
            return true
          }
        })
      } else { //val为空时,还原数组
        this.gzsFilter = this.gzs;
      }
    },

4. /** 选择工种 下拉框*/
    getGzList() {
      listGz().then(response => {
        this.gzs = response.rows;
        this.gzsFilter = response.rows;
      });
    },

5.return中声明

 gzsFilter:[],

6.create中声明

 this.getGzList();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值