-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvue-bind-event.html
57 lines (57 loc) · 1.59 KB
/
vue-bind-event.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<script src="./vue.js"></script>
</head>
<body>
<div id="app">
<div id="example-1">
<button @click="counter += 1">Add 1</button>
<p>The button above has been clicked {{counter}} times</p>
</div>
<div id="example-2">
<button @click="greet">Greet</button>
</div>
<div id="example-3">
<button @click="say('hi')">Say hi</button>
<button @click="say('what')">Say what</button>
</div>
<div id="example-4">
<button @click="warn('Form cannot be submitted yet', $event)"></button>
</div>
</div>
<script>
const data = { counter: 0, name: "Vue.js" };
const vm = new Vue({
el: "#app",
data,
watch: {},
computed: {},
methods: {
greet: function (event) {
// `this` 在方法里面指向当前 Vue 实例
alert("Hello " + this.name + "!");
// `event` 是原生 DOM 事件
if (event) {
alert(event.target.tagName);
}
},
say: function (message) {
alert(message);
},
warn: function (message, event) {
if (event) {
event.preventDefault();
}
alert(message);
},
},
mounted: function () {},
});
</script>
</body>
</html>