第一种给click后面添加stop

<div id="app">
<div @click="on2()">
<!--<input type="button" value="冒泡" @click.stop="on()"/>第一种给click后面添加stop-->

                                                                 
</div>

new Vue({
el:"#app",
methods:{

on:function(){
alert(1)

},
on2:function(){
alert(2)
}

}
})

-->

第二种是事件对象$event

<div id="app">
<div @click="on2()">

<input type="button" value="冒泡" @click="on($event)"/>
                                                             
                                                                 
</div>
</div>

<input type="button" value="冒泡" @click="on($event)"/>

  <script>
new Vue({
el:"#app",

on:function(ev){
alert(1)
ev.cancelBubble=true
},
on2:function(){
alert(2)
}

}
})

-->

Logo

前往低代码交流专区

更多推荐