vue事件对象、冒泡、阻止默认行为

事件对象:

            <input type="button" name="" value="按钮" @click="show($event)">
            methods: {
                show: function(ev) {
                    alert(ev.clientX);
                    alert(ev.clientY);
                }
            }

 

事件冒泡:

            <div @click="show2()">
                <input type="button" name="" value="按钮" @click.stop="show()">
            </div>
            methods: {
                show: function() {
                    alert(111);
                    //原生的写法
                    //ev.cancelBubble = true;
                },
                show2: function() {
                    alert(222);
                }
            }

 

阻止事件默认行为:

            <input type="button" name="" value="按钮" @contextmenu.prevent="show()">
            methods: {
                show: function() {
                    alert(111)
                },
                show2: function() {
                    alert(222)
                }
            }

 

posted @ 2018-03-28 10:29  谭翔随笔  阅读(138)  评论(0编辑  收藏  举报