vue cancels event bubbling] ; 2. [vue.js] prevents default events."/> vue cancels event bubbling] ; 2. [vue.js] prevents default events.">

Home >Web Front-end >Vue.js >How to prevent events from bubbling in vue.js

How to prevent events from bubbling in vue.js

coldplay.xixi
coldplay.xixiOriginal
2020-11-10 13:45:313078browse

vue.js method to prevent event bubbling: 1. [vue.js] cancel event bubbling, the code is [3c01280be79d064469c568c1b55fe1favue cancel Event bubbling16b28748ea4df4d9c2150843fecfba68]; 2. [vue.js] prevents default events.

How to prevent events from bubbling in vue.js

[Related article recommendations: vue.js]

vue.js blocking events Bubbling method:

Native js cancels event bubbling

    try{
        e.stopPropagation();//非IE浏览器
    }
    catch(e){
        window.event.cancelBubble = true;//IE浏览器
    }

Native js blocks default event

if ( e && e.preventDefault ) {
            e.preventDefault()//非IE浏览器
} else { window.event.returnValue = false; } //IE浏览器

vue.js cancel event bubbling

<div @click.stop="doSomething($event)">vue取消事件冒泡</div>

vue.js prevent default event

<div @click.prevent="doSomething($event)">vue阻止默认事件</div>

Related free learning recommendations: JavaScript(Video)

The above is the detailed content of How to prevent events from bubbling in vue.js. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn