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

99
Visualizações
Wait for event to fire before blurring

I have an autocomplete input, and when I click on an element, it does something. For simplification purposes, the thing is here "console.log(element)". The thing is that when I click an element, it blurs the input, and blurring the input destroys the elements of the list. If I wait a few milliseconds, the click event is handled, but if not, it only takes into account the blur event. I made an example with the two options:

var app = new Vue({
  el: '#app',
  data: {
    list: ['1', '2'],
  },
  methods: {
    handleBlurWithPause: async function () {
      await new Promise((r) => setTimeout(r, 300));
      console.log('Blurred with pause');
      this.list = [];
    },
    handleBlur: function () {
      console.log('Blurred');
      this.list = [];
    },
    handleClick: function (e) {
      console.log(e);
    },
    resetList: function () {
      this.list = ['1','2'];
    }
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  <input
    placeholder="With pause"
    type="text"
    @blur="handleBlurWithPause" />
  <input
    placeholder="Without pause"
    type="text"
    @blur="handleBlur" />
  <ul>
    <li
      v-for="elt in list"
      @click="handleClick(elt)">
      {{ elt }}
    </li>
  </ul>
  <button
    @click="resetList">
    Reset
  </button>
</div>

My question is: is there a better way to wait for the click event before handling the blur event? The async/await line seems very amateur for me.

Thanks in advance.

about 4 years ago · Juan Pablo Isaza
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