【问题标题】:How can I get it fast with text-field watch?如何使用文本字段手表快速获得它?
【发布时间】:2021-03-09 11:55:49
【问题描述】:

我在文本字段中输入输入值作为参数。但是每次我按下一个键时它的工作速度都很慢。我怎样才能加快速度。 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();
         }
       }
    }
}

【问题讨论】:

    标签: javascript vue.js vuetify.js


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2015-09-04
      • 2021-12-15
      • 2017-04-15
      • 1970-01-01
      • 1970-01-01
      • 2021-11-23
      • 2014-07-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多