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

150
Views
Function with parameters does not run inside Javascript AddEventListener

In NuxtJS I am trying to run a function with two parameters when an element is clicked with an AddEventListener.

async handleSubmit(recipe, userRating) {some code...}

setup(recipe) {
  document.querySelectorAll('.recipe-rating > .star').forEach(function(el) {
    el.addEventListener('click', function(el) {
        const userRating = el.currentTarget.getAttribute('data-rating');
        this.handleSubmit(recipe, userRating);
    }, false);
  });
...more code...
}

All of the code is within methods: {}, and I get the following error when clicking.

Uncaught TypeError: this.handleSubmit is not a function at SVGSVGElement.eval

How can I fix the problem, and what is the problem with my code?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

On way around this problem is to use Vue.js with the HTML element instead of trough a .js file. With v-on:click (se Vue docs) we can run a function when the user clicks the HTML element.

<svg v-for="(el, i) in 5" :key="i" :data-rating="el" @click="handleSubmit(recipe, el)">
  <polygon />
</svg>

Note: v-on:click changes to @click with ESLint.

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!