Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

167
Visualizações
When I type to fast on input it renders the wrong div

I'm have to show two different dropdown in my input. I'm doing it by having an shouldShowWarningBox method that it's called every time the input is updated by the user an updates the value of showWarningBox. The point is, when I type to fast I receive a false showing the warning message, but it's not true. If I type slowly the first div is rendered.

I've tried with and without the debounce function, but the behavior is the same, just with a little delay.

Any ideas?

.html

<div v-if="!showWarningBox">
 //dropbox
</div>

<div v-if="showWarningBox">
 //warning message
</div>

.js

data () {
 return {
  showWarningBox: false,
 }
},
methods: {
 onInput (value) {
  this.debounce(this.shouldShowWarningBox(), 1000)
 },
 shouldShowWarningBox () {
  //conditional that changes showWarningBox
 },
 debounce (func, delay) {
  let id
 
  return (...args) => {
   if (id) clearTimeout(id)

   id = setTimeout(() => {
    func(...args)
   }, delay)
  }
 },
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

debounce returns a "debounced" function. You should save that function in a component property and call that debounced function on input:

data(){
  let debouncedFn = this.debounce(this.shouldShowWarningBox, 1000)
  return {
    debouncedInput: debouncedFn
  }
},
methods: {
 onInput (value) {
  this.debouncedInput()
 },
 //...
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda