S
S
semki0962019-03-06 13:05:35
Vue.js
semki096, 2019-03-06 13:05:35

How to delegate an event in vuejs?

There is a simple example in the docs:

<div id="example-1">
  <button v-on:click="counter += 1">+1</button>
  <p>Кнопка выше была нажата {{ counter }} раз</p>
</div>

But what if there are 100 buttons for example? Is it possible to somehow hang v-on: click on the parent? That is, something like this
<div v-on:click="counter += 1" id="example-1">
<button>+1</button>
<button>+1</button>
<button>+1</button>
...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-03-06
@semki096

Just like without vue - look at event.target, act according to circumstances:
https://jsfiddle.net/rdcem751/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question