首页 > 解决方案 > 如何使用文本字段手表快速获得它?

问题描述

我在文本字段中输入输入值作为参数。但是每次我按下一个键时它的工作速度都很慢。我怎样才能加快速度。html代码

<v-col cols="3">
    <v-text-field
      v-model="registerSearch">
    </v-text-field>
</v-col>

脚本代码

 watch: {
    async registerSearch(value){
       if(value){
         if(this.registerSearch.length == 10 || this.registerSearch.length == 11){
           this.customer.TaxNumber=this.registerSearch;
           if(this.registerSearch.length == 11){
             await this.$validator.reset();
             
           }else{
             this.searched=false;
           }
         else{
           this.Search=[]
           this.customer.Company=''
           this.customer.FirstName=''
           this.customer.LastName=''
           this.searched = false;
           this.disableControl=true;
           await this.$validator.reset();
         }
       }
    }
}

标签: javascriptvue.jsvuetify.js

解决方案


可以尝试对您的搜索做一些延迟。用户输入几个字符后才开始搜索。这是 lodash decounce 示例。

import _ from 'lodash'

methods: {
    onChanged: _.debounce(function (event) {
        // search method here...  
    }, 300),
}

推荐阅读