-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent-handling.html
94 lines (83 loc) · 2.31 KB
/
event-handling.html
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<div id="app-1">
<button @click='counter +=1'>add 1</button>
<p>the button above has been clicked {{counter}} times</p>
<button @click='greet'>greet</button>
<button @click='say("hi")'>say hi</button>
<button @click='say("what")'>say what</button>
<button @click='warn("form cannot be submitted yet.", $event)'>submit</button>
<a href="http://test.com" v-on:click.stop="doThis">this is a test</a>
<form @submit.prevent='onSubmit'>
<button type="submit">submit form</button>
</form>
<a href="http://test.com" @click.stop.prevent='doThat'>stop and prevent</a>
<form @submit.prevent>
<button type="submit">submit form only prevent</button>
</form>
<div @click.capture='doThis'>capture</div>
<div @click.self='doThat'>
only this do that
<div @click='doThis'>do this</div>
</div>
<a @click.once='doThis'> do this once</a>
<div @scroll.passive='onScroll' style="height: 50px; background-color:cyan; overflow: scroll;">
<ol>
<li v-for="n in 10" :key="n">{{n}}</li>
</ol>
</div>
<input type="text" @keyup.enter='onEnter' placeholder="press enter to complete">
<input type="text" @keyup.alt.67='clear' placeholder="alt + C">
<button @click.ctrl='onCtrlTap'>onCtrlTap</button>
</div>
<script>
var app1 = new Vue({
el: '#app-1',
data: {
counter: 0,
name: 'world'
},
methods: {
greet(evnet) {
alert(`hello, ${this.name} !`);
if(event) {
alert(evnet.target.tagName);
}
},
say(str) {
alert(str);
},
warn(msg, event) {
if(event) event.preventDefault();
alert(msg);
},
doThis() {
alert('doThis')
},
onEnter() {
alert('onEnter');
},
doThat() {
alert('doThat');
},
onScroll() {
console.log('onScroll');
},
submit() {
console.log(submit);
},
clear() {
console.log('clear');
},
onCtrlTap() {
console.log('onCtrlTap');
}
}
})
</script>
</body>
</html>