7
7
<p >computed msg: {{ computedMsg }}</p >
8
8
<Hello ref =" helloComponent" />
9
9
<World />
10
- <button @click =" greet" >Greet</button >
11
10
12
- Clicked: {{ $store.state.count }} times, count is {{ evenOrOdd }}.
13
- <button @click =" increment" >+</button >
14
- <button @click =" decrement" >-</button >
15
- <button @click =" incrementIfOdd" >Increment if odd</button >
16
- <button @click =" incrementAsync" >Increment async</button >
11
+ <p >
12
+ <button @click =" greet" >Greet</button >
13
+ </p >
14
+
15
+ <p >
16
+ Clicked: {{ count }} times
17
+ <button @click =" increment" >+</button >
18
+ </p >
17
19
</div >
18
20
</template >
19
21
@@ -22,7 +24,7 @@ import Vue from 'vue'
22
24
import Component from ' ../../lib/index'
23
25
import Hello from ' ./components/Hello.vue'
24
26
import World from ' ./components/World'
25
- import { mapGetters , mapActions } from ' vuex'
27
+ import { mapState , mapMutations } from ' vuex'
26
28
27
29
// We declare the props separately
28
30
// to make props types inferable.
@@ -37,14 +39,13 @@ const AppProps = Vue.extend({
37
39
Hello ,
38
40
World
39
41
},
40
- // mapGetters & mapActions example
41
- computed: mapGetters ([
42
- ' evenOrOdd'
42
+
43
+ // Vuex's component binding helper can use here
44
+ computed: mapState ([
45
+ ' count'
43
46
]),
44
- methods: mapActions ([
45
- ' increment' ,
46
- ' decrement' ,
47
- ' incrementAsync'
47
+ methods: mapMutations ([
48
+ ' increment'
48
49
])
49
50
})
50
51
export default class App extends AppProps {
@@ -54,6 +55,16 @@ export default class App extends AppProps {
54
55
// use prop values for initial data
55
56
helloMsg: string = ' Hello, ' + this .propMessage
56
57
58
+ // annotate refs type
59
+ $refs! : {
60
+ helloComponent: Hello
61
+ }
62
+
63
+ // additional declaration is needed
64
+ // when you declare some properties in `Component` decorator
65
+ count! : number
66
+ increment! : () => void
67
+
57
68
// lifecycle hook
58
69
mounted () {
59
70
this .greet ()
@@ -74,10 +85,5 @@ export default class App extends AppProps {
74
85
incrementIfOdd() {
75
86
this .$store .dispatch (' incrementIfOdd' )
76
87
}
77
-
78
- // dynamic component
79
- $refs! : {
80
- helloComponent: Hello
81
- }
82
88
}
83
89
</script >
0 commit comments