2021-09-17 00:18:50 +08:00
|
|
|
<template>
|
2022-11-26 13:52:04 +08:00
|
|
|
<el-row class="demo-autocomplete">
|
2021-09-17 00:18:50 +08:00
|
|
|
<el-col :span="12">
|
2021-12-12 17:54:21 +08:00
|
|
|
<div class="sub-title my-2 text-sm text-gray-600">
|
|
|
|
list suggestions when activated
|
|
|
|
</div>
|
2021-09-17 00:18:50 +08:00
|
|
|
<el-autocomplete
|
|
|
|
v-model="state1"
|
|
|
|
:fetch-suggestions="querySearch"
|
2022-03-29 15:48:50 +08:00
|
|
|
clearable
|
2022-04-23 08:39:21 +08:00
|
|
|
class="inline-input w-50"
|
2021-09-17 00:18:50 +08:00
|
|
|
placeholder="Please Input"
|
|
|
|
@select="handleSelect"
|
|
|
|
/>
|
|
|
|
</el-col>
|
|
|
|
<el-col :span="12">
|
2021-12-12 17:54:21 +08:00
|
|
|
<div class="sub-title my-2 text-sm text-gray-600">
|
|
|
|
list suggestions on input
|
|
|
|
</div>
|
2021-09-17 00:18:50 +08:00
|
|
|
<el-autocomplete
|
|
|
|
v-model="state2"
|
|
|
|
:fetch-suggestions="querySearch"
|
|
|
|
:trigger-on-focus="false"
|
2022-03-29 15:48:50 +08:00
|
|
|
clearable
|
2022-04-23 08:39:21 +08:00
|
|
|
class="inline-input w-50"
|
2021-09-17 00:18:50 +08:00
|
|
|
placeholder="Please Input"
|
|
|
|
@select="handleSelect"
|
|
|
|
/>
|
|
|
|
</el-col>
|
|
|
|
</el-row>
|
|
|
|
</template>
|
2022-04-23 08:39:21 +08:00
|
|
|
|
2021-12-15 17:32:09 +08:00
|
|
|
<script lang="ts" setup>
|
2022-03-25 15:35:56 +08:00
|
|
|
import { onMounted, ref } from 'vue'
|
2021-12-15 17:32:09 +08:00
|
|
|
|
|
|
|
interface RestaurantItem {
|
|
|
|
value: string
|
|
|
|
link: string
|
|
|
|
}
|
|
|
|
|
|
|
|
const state1 = ref('')
|
|
|
|
const state2 = ref('')
|
|
|
|
|
|
|
|
const restaurants = ref<RestaurantItem[]>([])
|
|
|
|
const querySearch = (queryString: string, cb: any) => {
|
|
|
|
const results = queryString
|
|
|
|
? restaurants.value.filter(createFilter(queryString))
|
|
|
|
: restaurants.value
|
|
|
|
// call callback function to return suggestions
|
|
|
|
cb(results)
|
|
|
|
}
|
|
|
|
const createFilter = (queryString: string) => {
|
|
|
|
return (restaurant: RestaurantItem) => {
|
|
|
|
return (
|
|
|
|
restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const loadAll = () => {
|
|
|
|
return [
|
|
|
|
{ value: 'vue', link: 'https://github.com/vuejs/vue' },
|
|
|
|
{ value: 'element', link: 'https://github.com/ElemeFE/element' },
|
|
|
|
{ value: 'cooking', link: 'https://github.com/ElemeFE/cooking' },
|
|
|
|
{ value: 'mint-ui', link: 'https://github.com/ElemeFE/mint-ui' },
|
|
|
|
{ value: 'vuex', link: 'https://github.com/vuejs/vuex' },
|
|
|
|
{ value: 'vue-router', link: 'https://github.com/vuejs/vue-router' },
|
|
|
|
{ value: 'babel', link: 'https://github.com/babel/babel' },
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
const handleSelect = (item: RestaurantItem) => {
|
|
|
|
console.log(item)
|
|
|
|
}
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
restaurants.value = loadAll()
|
2021-09-17 00:18:50 +08:00
|
|
|
})
|
|
|
|
</script>
|