File tree Expand file tree Collapse file tree 3 files changed +16
-32
lines changed Expand file tree Collapse file tree 3 files changed +16
-32
lines changed Original file line number Diff line number Diff line change 71
71
"name" : " Mary Gordon"
72
72
}
73
73
]
74
- },
75
- {
76
- "id" : 2564147 ,
77
- "user" : {
78
- "id" : " abc123" ,
79
- "name" : " Adam Jahr"
80
- },
81
- "category" : " nature" ,
82
- "organizer" : {
83
- "id" : " abc123" ,
84
- "name" : " Adam Jahr"
85
- },
86
- "title" : " Working?" ,
87
- "description" : " " ,
88
- "___location" : " " ,
89
- "date" : " " ,
90
- "time" : " " ,
91
- "attendees" : []
92
74
}
93
75
]
94
76
}
Original file line number Diff line number Diff line change @@ -21,13 +21,25 @@ export default new Vuex.Store({
21
21
mutations : {
22
22
ADD_EVENT ( state , event ) {
23
23
state . events . push ( event )
24
+ } ,
25
+ SET_EVENTS ( state , events ) {
26
+ state . events = events
24
27
}
25
28
} ,
26
29
actions : {
27
30
createEvent ( { commit } , event ) {
28
31
return EventService . postEvent ( event ) . then ( ( ) => {
29
32
commit ( 'ADD_EVENT' , event )
30
33
} )
34
+ } ,
35
+ fetchEvents ( { commit } ) {
36
+ EventService . getEvents ( )
37
+ . then ( response => {
38
+ commit ( 'SET_EVENTS' , response . data )
39
+ } )
40
+ . catch ( error => {
41
+ console . log ( 'There was an error:' , error . response )
42
+ } )
31
43
}
32
44
} ,
33
45
getters : {
Original file line number Diff line number Diff line change 7
7
8
8
<script >
9
9
import EventCard from ' @/components/EventCard.vue'
10
- import EventService from ' @/services/EventService.js '
10
+ import { mapState } from ' vuex '
11
11
12
12
export default {
13
13
components: {
14
14
EventCard
15
15
},
16
- data () {
17
- return {
18
- events: []
19
- }
20
- },
21
16
created () {
22
- EventService .getEvents ()
23
- .then (response => {
24
- this .events = response .data
25
- })
26
- .catch (error => {
27
- console .log (' There was an error:' , error .response )
28
- })
29
- }
17
+ this .$store .dispatch (' fetchEvents' )
18
+ },
19
+ computed: mapState ([' events' ])
30
20
}
31
21
</script >
You can’t perform that action at this time.
0 commit comments