-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path19.v-on.html
46 lines (41 loc) · 1.11 KB
/
19.v-on.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
<!--
We can use the v-on directive to
listen to DOM events and run some JavaScript when they’re triggered.
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>v-on </title>
<script type="text/javascript"src="vue.js"></script>
</head>
<body>
<div id="main">
<!-- example 1 : 变量-->
<button v-on:click=" counter += 1 "> Add 1 </button>
<p>The button above has been clicked {{ counter }} times.</p>
<!-- example 2 : 不带参函数-->
<button v-on:click="greet">Greet</button>
<!-- example 3 : 带参函数-->
<button v-on:click="say('hi')">Say hi</button>
<button v-on:click="say('what')">Say what</button>
</div>
</body>
<script type="text/javascript">
var vm = new Vue({
el: '#main',
data: {
counter: 0
},
methods:{
greet: function (event) {
// `event` is the native DOM event
alert(event.target)
},
say:function(message){
alert(message)
}
}
});
</script>
</html>