123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <template>
- <div class="flex flex-wrap">
- <div class="m-4">
- <p>default</p>
- <el-select
- v-model="value"
- multiple
- filterable
- remote
- reserve-keyword
- placeholder="Please enter a keyword"
- :remote-method="remoteMethod"
- :loading="loading"
- >
- <el-option
- v-for="item in options"
- :key="item.value"
- :label="item.label"
- :value="item.value"
- />
- </el-select>
- </div>
- <div class="m-4">
- <p>use remote-show-suffix</p>
- <el-select
- v-model="value"
- multiple
- filterable
- remote
- reserve-keyword
- placeholder="Please enter a keyword"
- remote-show-suffix
- :remote-method="remoteMethod"
- :loading="loading"
- >
- <el-option
- v-for="item in options"
- :key="item.value"
- :label="item.label"
- :value="item.value"
- />
- </el-select>
- </div>
- </div>
- </template>
- <script lang="ts" setup>
- import { onMounted, ref } from 'vue'
- interface ListItem {
- value: string
- label: string
- }
- const list = ref<ListItem[]>([])
- const options = ref<ListItem[]>([])
- const value = ref<string[]>([])
- const loading = ref(false)
- onMounted(() => {
- list.value = states.map((item) => {
- return { value: `value:${item}`, label: `label:${item}` }
- })
- })
- const remoteMethod = (query: string) => {
- if (query) {
- loading.value = true
- setTimeout(() => {
- loading.value = false
- options.value = list.value.filter((item) => {
- return item.label.toLowerCase().includes(query.toLowerCase())
- })
- }, 200)
- } else {
- options.value = []
- }
- }
- const states = [
- 'Alabama',
- 'Alaska',
- 'Arizona',
- 'Arkansas',
- 'California',
- 'Colorado',
- 'Connecticut',
- 'Delaware',
- 'Florida',
- 'Georgia',
- 'Hawaii',
- 'Idaho',
- 'Illinois',
- 'Indiana',
- 'Iowa',
- 'Kansas',
- 'Kentucky',
- 'Louisiana',
- 'Maine',
- 'Maryland',
- 'Massachusetts',
- 'Michigan',
- 'Minnesota',
- 'Mississippi',
- 'Missouri',
- 'Montana',
- 'Nebraska',
- 'Nevada',
- 'New Hampshire',
- 'New Jersey',
- 'New Mexico',
- 'New York',
- 'North Carolina',
- 'North Dakota',
- 'Ohio',
- 'Oklahoma',
- 'Oregon',
- 'Pennsylvania',
- 'Rhode Island',
- 'South Carolina',
- 'South Dakota',
- 'Tennessee',
- 'Texas',
- 'Utah',
- 'Vermont',
- 'Virginia',
- 'Washington',
- 'West Virginia',
- 'Wisconsin',
- 'Wyoming',
- ]
- </script>
|