77 <p >computed msg: {{ computedMsg }}</p >
88 <Hello ref =" helloComponent" />
99 <World />
10- <button @click =" greet" >Greet</button >
1110
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 >
1719 </div >
1820</template >
1921
@@ -22,7 +24,7 @@ import Vue from 'vue'
2224import Component from ' ../../lib/index'
2325import Hello from ' ./components/Hello.vue'
2426import World from ' ./components/World'
25- import { mapGetters , mapActions } from ' vuex'
27+ import { mapState , mapMutations } from ' vuex'
2628
2729// We declare the props separately
2830// to make props types inferable.
@@ -37,14 +39,13 @@ const AppProps = Vue.extend({
3739 Hello ,
3840 World
3941 },
40- // mapGetters & mapActions example
41- computed: mapGetters ([
42- ' evenOrOdd'
42+
43+ // Vuex's component binding helper can use here
44+ computed: mapState ([
45+ ' count'
4346 ]),
44- methods: mapActions ([
45- ' increment' ,
46- ' decrement' ,
47- ' incrementAsync'
47+ methods: mapMutations ([
48+ ' increment'
4849 ])
4950})
5051export default class App extends AppProps {
@@ -54,6 +55,16 @@ export default class App extends AppProps {
5455 // use prop values for initial data
5556 helloMsg: string = ' Hello, ' + this .propMessage
5657
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+
5768 // lifecycle hook
5869 mounted () {
5970 this .greet ()
@@ -74,10 +85,5 @@ export default class App extends AppProps {
7485 incrementIfOdd() {
7586 this .$store .dispatch (' incrementIfOdd' )
7687 }
77-
78- // dynamic component
79- $refs! : {
80- helloComponent: Hello
81- }
8288}
8389 </script >
0 commit comments