Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Vue.js Basics What a Beautiful Vue! Basic Event Handling

Hai Huang
Hai Huang
12,675 Points

Can I pass any arguments to the event handler function when using v-on directive?

I understand what the attribute (or more precisely, the directive) v-on:mouseover="functionToRun" does. I just noticed that the event handler function is not followed by a pair of parentheses.

So,

  1. I wonder if v-on:mouseover="functionToRun()" does the same thing.
  2. I wonder if I can pass any arguments to it using the data in the Vue instance (v-on:mouseover="functionToRun(this.title)", for example).

Thank you.

1 Answer

Steven Parker
Steven Parker
231,271 Points
  1. The handler value can be a function name or some script code, so yes, you can call the function or just name it.
  2. If you're calling functions as part of script code, they can be passed arguments.
Hai Huang
Hai Huang
12,675 Points

Thank you very much, Steven!