1. 效果展示:
2. 代码:
html部分:
<el-autocomplete
v-model.trim="state.groupName"
:fetch-suggestions="querySearchGroup"
:clearable="true"
placeholder="请输入"
:trigger-on-focus="false"
@select="handleGroup"
>
ts部分:
let state = reactive({
groupName: ''
})
interface GroupItem {
value: string
}
const groupNameArr = ref<GroupItem[]>([])
const querySearchGroup = (queryString: string, cb: any) => {
const results = queryString
? groupNameArr.value.filter(createFilter(queryString))
: groupNameArr.value
cb(results)
}
const createFilter = (queryString: string) => {
return (item: any) => {
return item.value.indexOf(queryString) === 0
}
}
const createFilterNum = (queryString: string) => {
return (item: any) => {
return item.value == queryString
}
}
const handleGroup = (item: any) => {
console.log(item)
}
onMounted(() => {
groupNameArr.value = groupArr
}
|