Vuetify autocomplete组件

本文介绍了如何在Vue项目中使用Vuetify的autocomplete组件,重点讲解了search-input.sync监听数据变化、update:search-input阻止默认事件以及keyup.enter键盘enter事件的用法,并提供了相关的Html、data、watch和methods部分的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、search-input.sync:在watch里面监听输入数据的变化进行查询操作。
2、update:search-input:用来阻止search-input.sync监听事件继续进行。
3、keyup.enter:键盘enter事件。

Html
<v-autocomplete
          class="selectBox"
          v-model="typeContent"
          item-text="allContent"
          item-value="fullname"
          :items="components"
          :loading="isLoading"
          :search-input.sync="changeInfo"
          @update:search-input="changeName"
          @keyup.enter="jumpPage"
          placeholder="e.g. benzene  salbutamol"
          no-data-text="no data"
          solo
          chips
          clearable
          hide-details
          hide-selected
      >
        <template v-slot:selection="{ attr, on, item, selected }">
            <span v-text="item.fullname"></span>
        </template>
        <template v-slot:item="data">
          <template>
            <v-list-item-content>
              <v-list-item-title> {{data.item.fullname}}<span style="color:#9e9e9e;">(Dimension:{{data.item.label_length}}</span></v-list-item-title>
              <v-list-item-subtitle v-html="data.item.sy"></v-list-item-subtitle>
            </v-list-item-content>
          </template>
        </template>
        <template v-slot:append-outer>
          <v-slide-x-reverse-transition
              mode="out-in"
          >
            <span style="padding-left: 10px;margin-top: -4px;cursor: pointer" @click="jumpPage">
              <v-icon large color="#fff">search</v-icon>
            </span>
          </v-slide-x-reverse-transition>
        </template>
    </v-autocomplete>
data
	typeContent:'',
    components: [],
    isLoading:false,
    changeInfo:null,
    isUpdating:false,
    updataChanggeInfo:null,
watch
changeInfo(val){
        if (this.updataChanggeInfo === null) return;
        this.isLoading = true;
        fetch(`http://database.bio-it.cn/full_name_search?where={"$text":{"$search":"${val}"}}`)
          .then(res => res.json())
          .then(res => {
            const {_items } = res;
            this.components = _items
            this.components.forEach(item=>{
              item['allContent'] = item.fullname + item.sy;
            })
          })
          .catch(err => {
            console.log(err)
          })
          .finally(() => (this.isLoading = false))
      },
methods
changeName(val){
   this.updataChanggeInfo = val;
},

博客园地址:https://www.cnblogs.com/Li–gm/p/12767378.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值