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

255
Vistas
Can I return a function from methods property in Vue and use it as event handler?

Can we do something like this in Vue or I have to use only arrow function.

<template>
<vue-component
 v-for="(data, index) in someArr"
 @someEvent="someMethodWrapper(data)" 
>
</vue-component>
</template>

<script>
 methods: {
  someMethodWrapper(data) {
   return (someotherData) => {
    this.setNewProperty = { [data]: someOtherData }
   }
  }
 }
</script>
about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

v-on binding can accept either a function or an expression as event handler. A function that an expression evaluates to won't be used as event handler in this case.

This code just executes someMethodWrapper and ignores a function it returns. It could be workable by explicitly calling it:

@someEvent="someMethodWrapper(data)($event)" 

At this point it doesn't serve a good purpose to make someMethodWrapper higher order function, it could change signature to fit the case better:

someMethodWrapper(someotherData, data) {...}

and

@someEvent="someMethodWrapper($event, data)" 
about 4 years ago · Santiago Gelvez 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