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

156
Views
La función con parámetros no se ejecuta dentro de Javascript AddEventListener

En NuxtJS, estoy tratando de ejecutar una función con dos parámetros cuando se hace clic en un elemento con 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... }

Todo el código está dentro de los methods: {} y aparece el siguiente error al hacer clic.

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

¿Cómo puedo solucionar el problema y cuál es el problema con mi código?

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

0

Una forma de solucionar este problema es usar Vue.js con el elemento HTML en lugar de a través de un archivo .js . Con v-on:click ( se Vue docs ) podemos ejecutar una función cuando el usuario hace clic en el elemento HTML .

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

Nota: v-on:click cambia a @click con 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!