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

187
Vistas
Curly braces when calling a function from html in vue js

when calling function, for example on click it doesn't matter if I write curly braces or not. It works in both scenarios. But I made a function, which fires custom event from a child. then I await it in a parent component and fire my function (which is in parent), to update state. I noticed when I write curly braces on that function, vue returns an error. why is that happening? (I'm new to vue js :) ).

function in a child component, which is invoked on click:

  toggleFavorite: function () {
          this.$emit("toggle-favorite", this.id);
        }

A child component rendered inside a parent

<friend-contact
      v-for="friend in friends"
      :data="friend"
      :key="friend.id"
      @toggle-favorite="toggleFavorite"> // if i write 'toggleFavorite()' here, I am 
                                         // geting an error
                                         
    </friend-contact>

A function which is fired on custom event

 toggleFavorite: function (id) {
      let friendToUpdate = this.friends.find((el) => el.id === id);
      friendToUpdate.favorite = !friendToUpdate.favorite;
    }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

An event doesn't matter, what matters here is whether a parameter is used in event handler or not.

@toggle-favorite="toggleFavorite" results in toggleFavorite being used as event handler.

@toggle-favorite="toggleFavorite()" results in toggleFavorite() expression being evaluated on event, with id parameter being undefined.

There is $event magic value that represents event parameter in event handler. In order to match the first syntax, it should be @toggle-favorite="toggleFavorite($event)".

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