element已经给我们提供了此方法,需要在el-select中绑定几个属性即可
通过remote-method来实现实时发起搜索请求
<el-select v-model="searchByName"
filterable
placeholder="请输入企业名称/姓名"
remote
clearable
@change="currentSel"
reserve-keyword
:remote-method="Tolikesearch">
<el-option
v-for="item in likesearch"
:key="item.userId"
:label="item.realName"
:value="item.userId">
</el-option>
</el-select>
js
//获取select option选中的值
currentSel(selVal) {
this.selectid=selVal
},
//搜索发起请求 传入值为当前select输入的值
Tolikesearch(query){
enterpriseOrUserList({name:query}).then(res=>{
this.likesearch=res.data
})
},
最终实现的效果