P
P
Phoen1xx2020-08-30 19:45:39
JavaScript
Phoen1xx, 2020-08-30 19:45:39

How, when clicking on child elements, to get the one on which the event handler was hung?

There is an element with an event handler and several child elements:

<div @click="test">
  <span>1</span>
  <span>2</span>
  <span>3</span>
</div>

How to get div inside test function?
Here is an example of how I tried to do it:
https://jsfiddle.net/tk6unjeb/
But I only get the span itself, and in this the vue instance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-08-30
@Phoen1xx

to this vue instance

As it should be, vue sets the instance of the component as the context for calling methods . Which is logical - otherwise it would be difficult to access other properties / methods of the component inside the method.
Use currentTarget .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question