-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11.2_事件修饰符.html
More file actions
37 lines (36 loc) · 897 Bytes
/
Copy path11.2_事件修饰符.html
File metadata and controls
37 lines (36 loc) · 897 Bytes
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
27
28
29
30
31
32
33
34
35
36
37
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<pre>
事件修饰符: 修饰事件的,比如阻止事件冒泡,阻止默认事件
</pre>
<div id="app" v-on:click="parentClick" style="border: 1px solid;height: 100px;">
<button v-on:click="subClick">sub</button>
<!-- 加了stop修饰符,阻止事件冒泡 -->
<button v-on:click.stop="subClick">sub</button>
<a href="http://www.baidu.com" v-on:click.stop.prevent="clickUrl">百度</a>
</div>
<script src="js/vue-2.1.3.js"></script>
<script>
var vm = new Vue({
el: '#app',
data: {},
methods: {
parentClick: function() {
alert('你点击了父元素');
},
subClick: function() {
alert('你点击了子元素');
},
clickUrl: function() {
alert('修饰符可以串联,阻止事件默认事件和冒泡;');
}
}
})
</script>
</body>
</html>