前端
<el-autocomplete
v-model="userQuery.realName"
:fetch-suggestions="querySearchAsync"
placeholder="请输入员工姓名"
@select="handleSelect"
clearable
style="width: 200px;margin-right: 9px"
:trigger-on-focus="false"
></el-autocomplete>
javascript
data() { // 定义变量和初始值
return {
detailData: {}
}
}
查询接口
methods: {
querySearchAsync(queryString, cb) {
//接口
employeeAPI.getTzUserName(queryString)
.then(response => {
//声明一个数组存后端的数据
let KnowledgeList = []
//循环遍历数据
response.data.forEach(item => {
//value是显示的名字 content是值(可写可不写)
KnowledgeList.push({"value": item.realName, "content": item.userId})
})
//返回数据回组件
cb(KnowledgeList);
});
},
//点击匹配值触发
handleSelect(item) {
this.detailData.resultRemark = item.content
},
}