vue阻止事件

点击按钮的话他会,执行show ,show1方法,依次弹出1,2。

 

怎么来阻止

<1> 利用我们上面讲过的event对象:  event.cancelBubble = true;   //这种就阻止了

vue阻止事件

    
    
    

    
        window.onload = function(){            var vm = new Vue({
                el:'#box',
                methods:{
                    show:function(event){
                        alert(1);
                        event.cancelBubble = true;
                    },
                    show1:function(){
                        alert(2);
                    }
                }
            });
        }    
   
        
             
        
    

vue阻止事件

 

<2>利用vue的方法阻止冒泡:给HTML元素绑定click事件的时候,改为@click.stop="show()"

vue阻止事件

    
    
    

    
        window.onload = function(){            var vm = new Vue({
                el:'#box',
                methods:{
                    show:function(event){
                        alert(1);                        //event.cancelBubble = true;                    },
                    show1:function(){
                        alert(2);
                    }
                }
            });
        }    
    
        
             
        
    

vue阻止事件

 

3.默认行为

比如contextmenu右键菜单

vue阻止事件

    
    
    
    

    
        window.onload = function(){            var vm = new Vue({
                el:'#box',
                methods:{
                    show:function(){
                        alert(1);
                    },
                    show1:function(){
                        alert(2);
                    }
                }
            });
        }    
    
         
         

        

//按钮右击点下去会依次出现 弹窗 1, 还有右击的默认菜单

        

//按钮1右击只出现 弹窗 2

    

vue阻止事件

@click.stop.prevent,相当于同时执行:
event.stopPropagation();
event.preventDefault(); 


网页题目:vue阻止事件
网页网址:http://tjjierui.cn/article/gceppg.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP