效果图:
实现思路:el-autocomplete
html代码:
<el-autocomplete
v-model="entityName"
:fetch-suggestions="querySearch"
:trigger-on-focus="false"
@select="handleSelect"
placeholder="请输入..."
autosize
>
</el-autocomplete>
js代码,依靠querySearch回调,拿到输入的queryString
async querySearch(queryString, callback) {
if(queryString && queryString.length > 0){
const entityRelatedList = await getListEntitiesByName(queryString)
const formatEntityList = entityRelatedList.data.map(item => {
return {
id: `${item.id}`,
value: `${item.entityCnName}`
}
})
callback(formatEntityList)
}
},