2
I’m trying to make that when I stop typing in the input, the system waits a second to do my search and return my result, but I’m not getting it. The system is being made in Vuejs
<input class="input" type="text" v-model="valorPesquisa1" v-on:keyup="searchApi6(valorPesquisa1, 1)" placeholder="Informe nome">
<input class="input" type="text" v-model="valorPesquisa2" v-on:keyup="searchApi6(valorPesquisa2, 2)" placeholder="Informe nome, CNPJ, CPF ou CUT">
<input class="input" type="text" v-model="valorPesquisa2" v-on:keyup="searchApi6(valorPesquisa3, 2)" placeholder="Informe nome, CNPJ, CPF ou CUT">
<input class="input" type="text" v-model="valorPesquisa2" v-on:keyup="searchApi6(valorPesquisa4, 2)" placeholder="Informe nome, CNPJ, CPF ou CUT">
searchApi6(val,box){
let typingTimer;
let doneTypingInterval = 1000;
clearTimeout(typingTimer);
if(val.length > 2){
typingTimer = setTimeout(function(){
switch(box){
case 1:
this.textArea1 = true
break;
case 2:
this.textArea2 = true
break;
case 3:
this.textArea3 = true
break;
case 4:
this.textArea4 = true
break;
}
axios.get(url+'ListaPessoa?Token='+localStorage['id']+'&Filtro='+val)
.then(response => {
switch(box){
case 1:
this.autocomplete1 = false;
break;
case 2:
this.autocomplete2 = false;
break;
case 3:
this.autocomplete3 = false;
break;
case 4:
this.autocomplete4 = false;
break;
}
this.searchPeople = response.data;
})
.catch(error => {
console.log(error);
})
}, doneTypingInterval);
}
}
data(){
return{
data: this.$route.params.data,
doctoBLID: this.$route.params.doctoBLID,
valorPesquisa1: '',
textArea1: true,
textArea2: true,
textArea3: true,
textArea4: true,
textPeople1: '',
textPeople2: '',
textPeople3: '',
textPeople4: '',
autocomplete1: true,
autocomplete2: true,
autocomplete3: true,
autocomplete4: true,
searchPeople: [],
bloco2: true,
bloco3: true,
bloco4: true,
textId1: '',
textId2: '',
textId3: '',
textId4: '',
valorPesquisa2: '',
valorPesquisa3: '',
valorPesquisa4: ''
}
}
But I’m not getting it
You can place the component object where you have the
valorPesquisa1
?– Sergio
valuePquery 1 is set in Vue date as white, ai it is in input v-model
– Rafael Augusto
Yes, that I imagined, but I wanted to see the JS you have in that component so I can answer the question with your corrected code.
– Sergio
The only place I use it is here <input class="input" type="text" v-model="valuePesquisa1" v-on:keyup="searchApi6(valuePesquisa1, 1)" placeholder="Enter name">
– Rafael Augusto
Rafael, there are some errors in the code. If you want to put your code I can help and give an answer. Without seeing your code I’ll be guessing and the answer is less useful for you. You should have that
valorPesquisa1
in thedata
also...– Sergio
@Sergio I edited the code, and added the whole date
– Rafael Augusto
Great. Do you have more inputs where you research this component? I see
valorPesquisa2
up to 4– Sergio
@Sergio put the other inputs there, they are 4 inputs that search, they use the same function, because they search in the same API
– Rafael Augusto