forked from mitevpi/vue-composition-api-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Counter.vue
61 lines (51 loc) · 1.13 KB
/
Counter.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
<template>
<div>
<h2>{{ msg }}</h2>
<button class="myButton" @click="increment">Increment</button>
<button class="myButton" @click="double">Double</button>
<h3>Number is: {{ state.count }}</h3>
<h4>{{ state.status }}</h4>
</div>
</template>
<script>
import { reactive, computed, watch, onMounted } from "@vue/composition-api";
export default {
props: {
msg: {
type: String,
required: true
}
},
setup() {
const state = reactive({
count: 0,
status: "",
doubleValue: computed(() => state.count * 2),
squareValue: computed(() => state.count * state.count)
});
// MATH OPERATIONS
function increment() {
state.count++;
state.status = "Incremented";
}
function double() {
state.count *= 2;
state.status = "Doubled";
}
// STATUS OPERATIONS
function welcomeMessage() {
state.status = "Counter Loaded";
}
// LIFECYCLE HOOKS
watch(() => console.log(state.count));
onMounted(() => welcomeMessage());
return {
state,
increment,
double
};
}
};
</script>
<style scoped>
</style>