Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

104
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda