File tree Expand file tree Collapse file tree 10 files changed +106
-9
lines changed Expand file tree Collapse file tree 10 files changed +106
-9
lines changed Original file line number Diff line number Diff line change 11<template >
22 <div >
3- Hello: Joe Fusco
3+ Hello: {{user.firstName}} {{user.lastName}}
44 </div >
55</template >
66
77<script type="text/babel">
88 import Vue from ' vue'
9+ import { mapState } from ' vuex'
910
1011 export default Vue .component (' app-header' , {
11- props : {
12-
13- }
12+ computed : mapState ([
13+ ' user '
14+ ])
1415 })
1516 </script >
Original file line number Diff line number Diff line change 1+ 'use strict'
2+
3+ export const LOCAL_USER = 'vue.user'
Original file line number Diff line number Diff line change 11<template >
22 <div >
33 <h2 >Edit user</h2 >
4+
5+ <input v-model =" user.firstName" placeholder =" First name" />
6+ <input v-model =" user.lastName" placeholder =" Last name" />
7+ <input v-model =" user.age" type =" number" placeholder =" Age" />
8+
9+ <select v-model =" user.gender" >
10+ <option value =" male" >male</option >
11+ <option value =" female" >female</option >
12+ </select >
13+
14+ <button v-on:click =" save" >save</button >
415 </div >
516</template >
617
718<script type="text/babel">
819 import Vue from ' vue'
20+ import { mapActions , mapState } from ' vuex'
21+
22+ export default {
23+ methods: {
24+ ... mapActions ([
25+ ' getUser' ,
26+ ' updateUser'
27+ ]),
28+
29+ save (){
30+ this .updateUser (this .user )
31+ }
32+ },
33+
34+ mounted (){
35+ this .getUser ()
36+ },
37+
38+ computed: mapState ([
39+ ' user'
40+ ])
41+ }
942 </script >
Original file line number Diff line number Diff line change 2323 loader,
2424 user
2525 },
26+
2627 methods: {
2728 ... mapActions ([
2829 ' getUsers'
2930 ])
3031 },
32+
3133 mounted (){
3234 this .getUsers (10 );
3335 },
36+
3437 computed: mapState ([
3538 ' users' ,
3639 ' loader'
Original file line number Diff line number Diff line change @@ -21,6 +21,6 @@ export default new Vuex.Store({
2121 user,
2222 loader
2323 } ,
24- strict : debug ,
24+ strict : false ,
2525 middlewares : debug ? [ createLogger ( ) ] : [ ]
2626} )
Original file line number Diff line number Diff line change 11'use strict' ;
22
3- export const SHOW_LOADER = 'SHOW_LOADER' ;
4- export const HIDE_LOADER = 'HIDE_LOADER' ;
3+ export const SHOW_LOADER = 'SHOW_LOADER'
4+ export const HIDE_LOADER = 'HIDE_LOADER'
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 11'use strict' ;
22
3+ import Vue from 'vue'
4+ import VueResource from 'vue-resource'
5+ import * as type from './types'
6+ import { LOCAL_USER } from '../../../constants/index'
7+
8+ function getLocalUser ( ) {
9+ return localStorage . getItem ( LOCAL_USER ) ;
10+ }
11+
12+ const actions = {
13+ getUser ( { commit } ) {
14+ const storedUser = getLocalUser ( )
15+
16+ commit ( type . GET_USER , {
17+ user : storedUser
18+ } )
19+ } ,
20+
21+ updateUser ( { commit } , user ) {
22+ localStorage . setItem ( LOCAL_USER , JSON . stringify ( user ) ) ;
23+
24+ commit ( type . UPDATE_USER , {
25+ user
26+ } )
27+ }
28+ }
29+
30+ export default actions ;
Original file line number Diff line number Diff line change 11'use strict' ;
22
3+ import * as type from './types'
4+ import actions from './actions'
5+
6+ const state = {
7+ firstName : 'Joe' ,
8+ lastName : 'Fusco' ,
9+ age : 32 ,
10+ gender : 'male'
11+ }
12+
13+ const mutations = {
14+ [ type . GET_USER ] ( state , action ) {
15+ if ( action . user !== null ) {
16+ const storedUser = JSON . parse ( action . user ) ;
17+
18+ Object . assign ( state , storedUser )
19+ }
20+ } ,
21+
22+ [ type . UPDATE_USER ] ( state , action ) {
23+ Object . assign ( state , action . user )
24+ }
25+ }
26+
27+ export default {
28+ state,
29+ mutations,
30+ actions
31+ }
Original file line number Diff line number Diff line change 11'use strict' ;
22
3+ export const GET_USER = 'GET_USER'
4+ export const UPDATE_USER = 'UPDATE_USER'
You can’t perform that action at this time.
0 commit comments