700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 在Vue中子组件click事件触发父组件mousedown事件

在Vue中子组件click事件触发父组件mousedown事件

时间:2019-03-21 14:48:46

相关推荐

在Vue中子组件click事件触发父组件mousedown事件

父组件中使用了@mousedown

<div @mousedown="handleMouseDown($event)"我是父组件按钮</div>handleMouseDown(e){// e.stopPropagation()// e.preventDefaultconsole.log("父组件点击了")}

方法就是子组件中不要使用click,也使用mousedown ,然后使用e.preventDefault()与e.stopPropagation()

<div @mousedown="handleMouseDown($event)"我是子组件按钮</div>handleMouseDown(e){e.stopPropagation()e.preventDefault()console.log("子组件点击了")}

挺简单的就是刚开始的时候没想到,在此记录下。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。