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

149
Vistas
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 Respuestas
Responde la pregunta

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 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