-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathevent-binding.vue
64 lines (56 loc) · 1.63 KB
/
event-binding.vue
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
<template>
<div>
<!-- You can ignore the structure of this .vue file for now. This will be covered in a later tutorial. -->
<!-- Let's start by calling the "joke" method on this button's click. -->
<button>Knock Knock!</button>
<br>
<!-- We have a counter and two buttons. Call their respective methods. -->
Count: {{ count }}
<button>Increase</button>
<button>Decrease</button>
<!-- Mouse events can also act as triggers. Call the "foo" method on "mouseover" and "bar" method on "mouseout". -->
<div v-bind:style="myStyle">Hover Over Me</div>
<!-- We can also trigger events on key presses. Call "myEvent" on "keyup.enter". -->
<input placeholder="Press the enter key...">
<br>
<!-- Refer the "shorthand" URL for an alternative syntax of v-on. Link that page here (remember the data-binding tutorial?). -->
Bonus:
<a href="#" target="_blank" rel="noopener noreferrer">Link</a>
</div>
</template>
<script>
export default {
data() {
return {
count: 0,
myStyle: {
fontWeight: 'bold',
backgroundColor: '#90EE90'
},
shorthand: 'https://vuejs.org/v2/guide/syntax.html#v-on-Shorthand'
}
},
methods: {
joke() {
alert('Who\'s there?');
},
increment() {
this.count += 1;
},
decrement() {
this.count -= 1;
},
foo() {
this.myStyle.backgroundColor = '#FFB6C1';
},
bar() {
this.myStyle.backgroundColor = '#90EE90';
},
myEvent() {
alert('You pressed Enter!');
}
}
}
</script>
<style scoped>
</style>