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

479
Vistas
Why is the focus event fired twice from a Vue 3 child component?

When I fire a focus event from a top level input field in Vue 3:

<input @focus="$emit('focus')">

...the event is fired once when the input field is focused (as I would expect).

However, when you put this same input field into a child component and focus it:

<InputField @focus="$emit('focus')" />

...the event is fired twice.

See https://stackblitz.com/edit/vue-wjhche?devToolsHeight=33&file=src/components/HelloWorld.vue

Can you please help me to understand why this is happening? Thanks!

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

So, you shouldn't put a focus event in the child component, and also in the input field too, as the child component already will bind its focus event to the input so the focus event will be called twice, as the input is the root element.

Just removing the focus event from the input will solve the issue.

https://stackblitz.com/edit/vue-676vsb?file=src/components/InputField.vue

about 4 years ago · Santiago Trujillo Denunciar
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