Showing
3 changed files
with
42 additions
and
9 deletions
| ... | @@ -12,6 +12,7 @@ | ... | @@ -12,6 +12,7 @@ |
| 12 | <child :level="1">Hello world!</child> | 12 | <child :level="1">Hello world!</child> |
| 13 | <child :level="3">Hello world!</child> | 13 | <child :level="3">Hello world!</child> |
| 14 | <my-paragraph></my-paragraph> | 14 | <my-paragraph></my-paragraph> |
| 15 | + <getters></getters> | ||
| 15 | </div> | 16 | </div> |
| 16 | </template> | 17 | </template> |
| 17 | 18 | ||
| ... | @@ -19,8 +20,7 @@ | ... | @@ -19,8 +20,7 @@ |
| 19 | import counter from './components/counter.vue' | 20 | import counter from './components/counter.vue' |
| 20 | import child from './components/child.vue' | 21 | import child from './components/child.vue' |
| 21 | import myParagraph from './components/myParagraph.vue' | 22 | import myParagraph from './components/myParagraph.vue' |
| 22 | - | 23 | +import getters from './components/getters.vue' |
| 23 | -import { store } from './main.js' | ||
| 24 | 24 | ||
| 25 | export default { | 25 | export default { |
| 26 | name: 'app', | 26 | name: 'app', |
| ... | @@ -31,25 +31,25 @@ export default { | ... | @@ -31,25 +31,25 @@ export default { |
| 31 | }, | 31 | }, |
| 32 | computed: { | 32 | computed: { |
| 33 | count() { | 33 | count() { |
| 34 | - return store.state.count | 34 | + return this.$store.state.count |
| 35 | }, | 35 | }, |
| 36 | isLogin() { | 36 | isLogin() { |
| 37 | - return store.state.isLogin | 37 | + return this.$store.state.isLogin |
| 38 | } | 38 | } |
| 39 | }, | 39 | }, |
| 40 | methods: { | 40 | methods: { |
| 41 | increment() { | 41 | increment() { |
| 42 | - store.commit('increment') | 42 | + this.$store.commit('increment') |
| 43 | }, | 43 | }, |
| 44 | decrement() { | 44 | decrement() { |
| 45 | - store.commit('decrement') | 45 | + this.$store.commit('decrement') |
| 46 | }, | 46 | }, |
| 47 | login() { | 47 | login() { |
| 48 | - store.commit('login') | 48 | + this.$store.commit('login') |
| 49 | } | 49 | } |
| 50 | }, | 50 | }, |
| 51 | components: { | 51 | components: { |
| 52 | - counter,child,myParagraph | 52 | + counter,child,myParagraph,getters |
| 53 | } | 53 | } |
| 54 | } | 54 | } |
| 55 | </script> | 55 | </script> | ... | ... |
src/components/getters.vue
0 → 100644
| 1 | +<template lang="html"> | ||
| 2 | + <div> | ||
| 3 | + doneTodos: {{doneTodos}} | ||
| 4 | + </div> | ||
| 5 | +</template> | ||
| 6 | + | ||
| 7 | +<script> | ||
| 8 | +export default { | ||
| 9 | + data () { | ||
| 10 | + return {} | ||
| 11 | + }, | ||
| 12 | + computed: { | ||
| 13 | + doneTodos (){ | ||
| 14 | + return this.$store.getters.doneTodos | ||
| 15 | + } | ||
| 16 | + }, | ||
| 17 | + mounted () {}, | ||
| 18 | + methods: {}, | ||
| 19 | + components: {} | ||
| 20 | +} | ||
| 21 | +</script> | ||
| 22 | + | ||
| 23 | +<style lang="css"> | ||
| 24 | +</style> |
| ... | @@ -8,7 +8,16 @@ const store = new Vuex.Store({ | ... | @@ -8,7 +8,16 @@ const store = new Vuex.Store({ |
| 8 | state: { | 8 | state: { |
| 9 | count: 0, | 9 | count: 0, |
| 10 | size: 10, | 10 | size: 10, |
| 11 | - isLogin: false | 11 | + isLogin: false, |
| 12 | + todos: [ | ||
| 13 | + { id: 1, text: '...', done: true }, | ||
| 14 | + { id: 2, text: '...', done: false } | ||
| 15 | + ] | ||
| 16 | + }, | ||
| 17 | + getters: { | ||
| 18 | + doneTodos: state => { | ||
| 19 | + return state.todos.filter(todo => todo.done) | ||
| 20 | + } | ||
| 12 | }, | 21 | }, |
| 13 | mutations: { | 22 | mutations: { |
| 14 | increment: state => state.count++, | 23 | increment: state => state.count++, | ... | ... |
-
Please register or login to post a comment