Event bubbling mechanism

Reference article: https://segmentfault.com/a/1190000015852875
     https://segmentfault.com/a/1190000008457972

Bubbling performance:

<div  v-for="(item, index) in listData" @click="handleClick3">
    <el-col :span="grid">
        <div @click="handleClick1"></div>
    </el-col>
    <el-col  @click="handleClick2">
    </el-col>
</div>     

Bubbling performance here is that when the user clicks the Event 1 or Event 2 area, 3 events will be executed. This is because the time bubbling mechanism, leading to click 'handleClick1' will respond 'handleClick3'. Most of the time this is not desirable, the same I do not want here.

Vue solution of

<div  v-for="(item, index) in listData" @click="handleClick3">
    <el-col :span="grid">
        <div @click.stop="handleClick1"></div>
    </el-col>
    <el-col  @click.stop="handleClick2">
    </el-col>
</div> 

In addition to bubble, vue modifiers also provide these functions.

<!-- 阻止单击事件继续传播 -->
<a v-on:click.stop="doThis"></a>

<!-- 提交事件不再重载页面 -->
<form v-on:submit.prevent="onSubmit"></form>

<!-- 修饰符可以串联 -->
<a v-on:click.stop.prevent="doThat"></a>

<!-- 只有修饰符 -->
<form v-on:submit.prevent></form>

<!-- 添加事件监听器时使用事件捕获模式 -->
<!-- 即元素自身触发的事件先在此处处理,然后才交由内部元素进行处理 -->
<div v-on:click.capture="doThis">...</div>

<!-- 只当在 event.target 是当前元素自身时触发处理函数 -->
<!-- 即事件不是从内部元素触发的 -->
<div v-on:click.self="doThat">...</div>
Published 80 original articles · won praise 82 · views 10000 +

Guess you like

Origin blog.csdn.net/qq_42893625/article/details/104019971