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

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

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