forked from mitevpi/vue-composition-api-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CounterVuex.vue
48 lines (40 loc) · 1.11 KB
/
CounterVuex.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
<template>
<div>
<h2>{{ "Welcome to Your Vue.js Functional API App With Vuex" }}</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";
import store from "../store";
export default {
setup() {
const state = reactive({
count: computed(() => store.getters.number),
status: computed(() => store.getters.status),
doubleValue: computed(() => state.count * 2),
squareValue: computed(() => state.count * state.count)
});
// MATH OPERATIONS
function increment() {
store.dispatch("INCREMENT_NUMBER");
}
function double() {
store.dispatch("DOUBLE_NUMBER");
}
// LIFECYCLE HOOKS
watch(() => console.log(state.count));
onMounted(() => store.dispatch("SET_STATUS", "Vuex Counter Loaded"));
return {
state,
increment,
double
};
}
};
</script>
<style scoped>
</style>