App.vue
2.2 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<template>
<div id="app">
<counter></counter>
<div class="">
{{isLogin}}
</div>
<p>
<!-- <button @click="increment">+</button> -->
<button @click="add">add</button>
<button @click="decrement">-</button>
<button @click="login">login</button>
<button @click="incrementAsync">incrementAsync</button>
</p>
<child :level="1">Hello world!</child>
<child :level="3">Hello world!</child>
<my-paragraph></my-paragraph>
<getters></getters>
<span>obj: {{obj}}</span>
<button @click="addObj">addObj</button>
<module></module>
</div>
</template>
<script>
import counter from './components/counter.vue'
import child from './components/child.vue'
import myParagraph from './components/myParagraph.vue'
import getters from './components/getters.vue'
import module from './components/module.vue'
import { mapMutations } from 'vuex'
export default {
name: 'app',
data() {
return {
}
},
computed: {
isLogin() {
return this.$store.state.isLogin
},
obj () {
return this.$store.state.obj
}
},
methods: {
// increment() {
// this.$store.commit('increment', {
// amount: 10
// })
// // this.$store.commit('increment', {
// // amount: 10
// // },{silent:true})
// // this.$store.commit({
// // type:'increment',
// // amount: 10
// // })
// },
decrement() {
this.$store.commit('decrement')
},
login() {
this.$store.commit('login')
},
addObj() {
this.$store.commit('addObj')
},
...mapMutations({
add: 'increment' // 映射 this.add() 到 this.$store.commit('increment')
}),
// ...mapMutations([
// 'increment' // 映射 this.increment() 到 this.$store.commit('increment')
// ]),
incrementAsync() {
this.$store.dispatch('incrementAsync')
}
},
components: {
counter,
child,
myParagraph,
getters,
module
}
}
</script>