javascript - 如何使用文本字段手表快速获得它?
问题描述
我在文本字段中输入输入值作为参数。但是每次我按下一个键时它的工作速度都很慢。我怎样才能加快速度。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();
}
}
}
}
解决方案
可以尝试对您的搜索做一些延迟。用户输入几个字符后才开始搜索。这是 lodash decounce 示例。
import _ from 'lodash'
methods: {
onChanged: _.debounce(function (event) {
// search method here...
}, 300),
}
推荐阅读
- multithreading - Flask同时为不同的网站访问者分配不同的ID,并将他们的输入信息写入json文件
- python - SymPy 中的非笛卡尔坐标积分
- java - 可选和 Java Spring 测试
- jquery - 当某些数字以k结尾时如何使用Jquery进行排序?
- bash - 比 shell 脚本更有效的 Bash 变量
- python - 合并或映射具有唯一列名或特定条件的 DataFrame
- perl - 将字符串拆分为哈希散列(perl)
- mysql - 无法从 Xampp 上的 phpMyadmin 导出数据库
- pyinstaller - 嘿,我无法正确安装 pyinstaller
- c - C:创建/使用头文件和 Cython、Cythonize setup.py、MSVC 和 GCC 问题需要明确吗?