Showing
3 changed files
with
22 additions
and
9 deletions
| 1 | <template> | 1 | <template> |
| 2 | <div id="app"> | 2 | <div id="app"> |
| 3 | <counter></counter> | 3 | <counter></counter> |
| 4 | + <div class=""> | ||
| 5 | + {{isLogin}} | ||
| 6 | + </div> | ||
| 4 | <p> | 7 | <p> |
| 5 | <button @click="increment">+</button> | 8 | <button @click="increment">+</button> |
| 6 | <button @click="decrement">-</button> | 9 | <button @click="decrement">-</button> |
| 10 | + <button @click="login">login</button> | ||
| 7 | </p> | 11 | </p> |
| 8 | <child :level="1">Hello world!</child> | 12 | <child :level="1">Hello world!</child> |
| 9 | <child :level="3">Hello world!</child> | 13 | <child :level="3">Hello world!</child> |
| ... | @@ -28,6 +32,9 @@ export default { | ... | @@ -28,6 +32,9 @@ export default { |
| 28 | computed: { | 32 | computed: { |
| 29 | count() { | 33 | count() { |
| 30 | return store.state.count | 34 | return store.state.count |
| 35 | + }, | ||
| 36 | + isLogin() { | ||
| 37 | + return store.state.isLogin | ||
| 31 | } | 38 | } |
| 32 | }, | 39 | }, |
| 33 | methods: { | 40 | methods: { |
| ... | @@ -36,6 +43,9 @@ export default { | ... | @@ -36,6 +43,9 @@ export default { |
| 36 | }, | 43 | }, |
| 37 | decrement() { | 44 | decrement() { |
| 38 | store.commit('decrement') | 45 | store.commit('decrement') |
| 46 | + }, | ||
| 47 | + login() { | ||
| 48 | + store.commit('login') | ||
| 39 | } | 49 | } |
| 40 | }, | 50 | }, |
| 41 | components: { | 51 | components: { | ... | ... |
| ... | @@ -13,13 +13,13 @@ export default { | ... | @@ -13,13 +13,13 @@ export default { |
| 13 | // // Yikes - duplicate VNodes! | 13 | // // Yikes - duplicate VNodes! |
| 14 | // myParagraphVNode, myParagraphVNode | 14 | // myParagraphVNode, myParagraphVNode |
| 15 | // ]) | 15 | // ]) |
| 16 | - return createElement('div', | 16 | + // return createElement('div', |
| 17 | - Array.apply(null, { | 17 | + // Array.apply(null, { |
| 18 | - length: 10 | 18 | + // length: 10 |
| 19 | - }).map(function() { | 19 | + // }).map(function() { |
| 20 | - return createElement('p', 'hi') | 20 | + // return createElement('p', 'hi') |
| 21 | - }) | 21 | + // }) |
| 22 | - ) | 22 | + // ) |
| 23 | } | 23 | } |
| 24 | } | 24 | } |
| 25 | </script> | 25 | </script> | ... | ... |
| ... | @@ -6,11 +6,14 @@ Vue.use(Vuex) | ... | @@ -6,11 +6,14 @@ Vue.use(Vuex) |
| 6 | 6 | ||
| 7 | const store = new Vuex.Store({ | 7 | const store = new Vuex.Store({ |
| 8 | state: { | 8 | state: { |
| 9 | - count: 0 | 9 | + count: 0, |
| 10 | + size: 10, | ||
| 11 | + isLogin: false | ||
| 10 | }, | 12 | }, |
| 11 | mutations: { | 13 | mutations: { |
| 12 | increment: state => state.count++, | 14 | increment: state => state.count++, |
| 13 | - decrement: state => state.count-- | 15 | + decrement: state => state.count--, |
| 16 | + login: state => state.isLogin = true | ||
| 14 | } | 17 | } |
| 15 | }) | 18 | }) |
| 16 | 19 | ... | ... |
-
Please register or login to post a comment