Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable propagation of click handle to child in vue 2

Tags:

vue.js

vuejs2

Using this markup

<div @click='handleClickOnDiv'>
    {{ message }}
    <i class='fa fa-plus' @click='handleClickOnI'></i>
</div>

When I click on div - it calls handleClickOnDiv, but when I click on i - it calls both handlers.

How to deal with it?

like image 356
Jackson J Avatar asked Feb 05 '23 23:02

Jackson J


1 Answers

Try Event-Modifiers with @click, you can do following:

<div @click='handleClickOnDiv'>
    {{ message }}
    <i class='fa fa-plus' @click.stop='handleClickOnI'></i>
</div>
like image 176
Saurabh Avatar answered Feb 17 '23 22:02

Saurabh