Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

186
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!