Vuetify autocomplete組件


1、search-input.sync:在watch里面監聽輸入數據的變化進行查詢操作。
2、update:search-input:用來阻止search-input.sync監聽事件繼續進行。
3、keyup.enter:鍵盤enter事件。

Html

 1  <v-autocomplete
 2           class="selectBox"
 3           v-model="typeContent"
 4           item-text="allContent"
 5           item-value="fullname"
 6           :items="components"
 7           :loading="isLoading"
 8           :search-input.sync="changeInfo"
 9           @update:search-input="changeName"
10           @keyup.enter="jumpPage"
11           placeholder="e.g. benzene  salbutamol"
12           no-data-text="no data"
13           solo
14           chips
15           clearable
16           hide-details
17           hide-selected
18       >
19         <template v-slot:selection="{ attr, on, item, selected }">
20             <span v-text="item.fullname"></span>
21         </template>
22         <template v-slot:item="data">
23           <template>
24             <v-list-item-content>
25               <v-list-item-title> {{data.item.fullname}}<span style="color:#9e9e9e;">(Dimension:{{data.item.label_length}})</span></v-list-item-title>
26               <v-list-item-subtitle v-html="data.item.sy"></v-list-item-subtitle>
27             </v-list-item-content>
28           </template>
29         </template>
30         <template v-slot:append-outer>
31           <v-slide-x-reverse-transition
32               mode="out-in"
33           >
34             <span style="padding-left: 10px;margin-top: -4px;cursor: pointer" @click="jumpPage">
35               <v-icon large color="#fff">search</v-icon>
36             </span>
37           </v-slide-x-reverse-transition>
38         </template>
39     </v-autocomplete>

data

1    typeContent:'',
2     components: [],
3     isLoading:false,
4     changeInfo:null,
5     isUpdating:false,
6     updataChanggeInfo:null,

watch

 

 1  changeInfo(val){
 2         if (this.updataChanggeInfo === null) return;
 3         this.isLoading = true;
 4         fetch(`http://database.bio-it.cn/full_name_search?where={"$text":{"$search":"${val}"}}`)
 5           .then(res => res.json())
 6           .then(res => {
 7             const {_items } = res;
 8             this.components = _items
 9             this.components.forEach(item=>{
10               item['allContent'] = item.fullname + item.sy;
11             })
12           })
13           .catch(err => {
14             console.log(err)
15           })
16           .finally(() => (this.isLoading = false))
17       },

 

methods

 

1 changeName(val){
2         this.updataChanggeInfo = val;
3      },

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM