事件修饰符可以串联,**@click.stop.prevent=’fun’**
1.阻止事件冒泡(.stop)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
<div id="app" @click="handleFather"> <button @click.stop="handle">click</button> </div> <script src="../../js/vue.js"></script> <script> let app = new Vue({ el: '#app', data: {
}, methods: { handleFather: function (){ alert('I am father!') }, handle: function (event){ alert('I am son!'); } } }) </script>
|
2.阻止默认行为(.prevent)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| <div id="app"> <a href="https://www.baidu.com" @click.prevent="handle">百度</a> </div> <script src="../../js/vue.js"></script> <script> let app = new Vue({ el: '#app', data: { }, methods: { handle: function (event){ console.log('点击了!'); } } }) </script>
|