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 trialHai Huang
12,675 PointsCan 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,
- I wonder if v-on:mouseover="functionToRun()" does the same thing.
- 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
231,236 Points- The handler value can be a function name or some script code, so yes, you can call the function or just name it.
- If you're calling functions as part of script code, they can be passed arguments.
Hai Huang
12,675 PointsHai Huang
12,675 PointsThank you very much, Steven!