elementUI使用el-autocomplete实现自动匹配

<el-autocomplete v-model="supplierName" :fetch-suggestions="querySearchAsync" placeholder="请输入供应商编号/名称" @select="handleSelect"></el-autocomple
te width="100%">
 
 
//选择供应商
        handleSelect:function(item){
          this.supplierId=item.ACCOUNTNUM;
          this.supplierName=item.NAME;
        },
        //自动匹配供应商
        querySearchAsync(queryString, callback) {  
          var list = [{}];  
          var that = this;
          axios.post(\'/index.php/supplier/list\',{
            supplier_name:that.supplierName
          }).then((response)=>{  
              for(let i of response.data.data.list){  
                  i.value = i.ACCOUNTNUM + "---" + i.NAME;
              }  
              list = response.data.data.list;  
              callback(list);  
          }).catch((error)=>{  
          console.log(error);  
          });  
        },
 

value = i.ACCOOUNTNUM + “---” + i.NAME给list对象添加一个新属性value是因为el-autocomplete下拉列中只识别value

Callback回调参数,将处理好的数据推回

猜你喜欢

转载自www.cnblogs.com/liuqianrong/p/9287960.html