vue2.0的contextmenu右键弹出菜单的实例代码
整理文档,搜刮出一个vue2.0的contextmenu右键弹出菜单的实例代码,稍微整理精简一下做下分享。
1.事情对象
window.onload=function(){ varvm=newVue({ el:'#box', methods:{ show:function(event){ console.log(event);//event这个就是事件对象了 } } }); }
通过show($event)把事件对象传到方法里
2.事件冒泡
window.onload=function(){ varvm=newVue({ el:'#box', methods:{ show:function(){ alert(1); }, show1:function(){ alert(2); } } }); }
点击按钮的话他会,执行show,show1方法,依次弹出1,2。
怎么来阻止
<1>利用我们上面讲过的event对象: event.cancelBubble=true; //这种就阻止了
window.onload=function(){ varvm=newVue({ el:'#box', methods:{ show:function(event){ alert(1); event.cancelBubble=true; }, show1:function(){ alert(2); } } }); }