如何阻止父级事件传递给子级?

<div class="common" @touchmove="move">
    <div class="son">
        xxxxxx
    </div>
</div>

move:function(e){
    let odiv = e.target; 
    console.log(odiv);//拖动父级就显示父级DOM,拖动子级就显示子级DOM,但我不想拖动子级该怎么做?
}
阅读 6.5k
4 个回答

vue默认冒泡,所以在父节点加stop只是阻止继续冒泡,改成@touchmove.capture.stop="move",在捕获节段拦截事件

事件有捕获,目标,和冒泡三个阶段。在捕获的时候触发就不会去下面了。可以使用addEventListener来注册事件

试一下@touchmove.stop="move"

加一个判断吧

move:function(e){
    let odiv = e.target; 
    while (odiv.$el.className!='common'&&odiv.$el.$parent) odiv = odiv.$parent;
    console.log(odiv);//拖动父级就显示父级DOM,拖动子级就显示子级DOM,但我不想拖动子级该怎么做?
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题