-
Notifications
You must be signed in to change notification settings - Fork 0
/
computed_x_method.html
49 lines (49 loc) · 1.18 KB
/
computed_x_method.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>VueJS</title>
<link rel="stylesheet" href="">
<script src="vue.js"></script>
</head>
<body>
<div id="app">
<button v-on:click="counter++"> Increase </button>
<button v-on:click="counter--"> Decrease </button>
<button v-on:click="increaseSecond++"> IncreaseSecond </button>
<p> Counter: {{ counter }} | {{ increaseSecond }} </p>
<p> Result: {{ result() }} | {{ output }}</p>
</div>
<script type="text/javascript">
new Vue({
el: '#app',
data: {
counter: 0,
result: 0,
increaseSecond: 0,
},
computed: {
output() {
return this.counter > 5 ? 'Greater 5' : 'Smaller than 5';
}
},
methods: {
result() {
console.log('Method');
return this.counter > 5 ? 'Greater 5' : 'Smaller than 5';
}
},
watch: {
counter: function(value) {
var vm = this;
// Closure callback
setTimeout(function() {
vm.counter = 0;
}, 2000);
}
}
})
</script>
</body>
</html>