0

I need to get the element calling my function in Vue. But there is no event. I'm calling the method in my v-for. Here is my HTML code:

<select id="sel_subUse" v-on:change="calculateARV(event, index)">
    <option v-for="subUse in filter(event, index)" value="subUse">{{ subUse }}</option>
</select>

I tried using event.target anyways but to no avail. How do I get the calling element?

1 Answer 1

1

You need to use $event, not event as the parameter. Then you'll have the event.

https://v2.vuejs.org/v2/guide/events.html#Methods-in-Inline-Handlers

Sign up to request clarification or add additional context in comments.

7 Comments

It doesn't work. I've used event without the $ sign in other places, and they work just fine.
You can ignore the link to the documentation if you'd like I guess.
Was that sarcasm? I followed the documentation. It doesn't work. There isn't an event (v-on:something) in this case. That's probably why it doesn't work.
Yes. Sorry. Are you talking about the event from here? v-on:change="calculateARV(event, index)". If so, that needs to become calculateARV($event, index) and in your callback the first argument will be the DOM event. If event is actual data you need (only suspecting it because of filter(event, index)) then you can do calculateARV(event, index, $event) then the third argument will be the DOM event.
If you were doing v-on:change="calculateARV" you wouldn't need to pass event yourself. It would be available as the first argument in the method.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.