File tree Expand file tree Collapse file tree 2 files changed +24
-15
lines changed Expand file tree Collapse file tree 2 files changed +24
-15
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,8 @@ export default new Vuex.Store({
17
17
'community'
18
18
] ,
19
19
events : [ ] ,
20
- eventsTotal : 0
20
+ eventsTotal : 0 ,
21
+ event : { }
21
22
} ,
22
23
mutations : {
23
24
ADD_EVENT ( state , event ) {
@@ -28,6 +29,9 @@ export default new Vuex.Store({
28
29
} ,
29
30
SET_EVENTS_TOTAL ( state , eventsTotal ) {
30
31
state . eventsTotal = eventsTotal
32
+ } ,
33
+ SET_EVENT ( state , event ) {
34
+ state . event = event
31
35
}
32
36
} ,
33
37
actions : {
@@ -48,6 +52,21 @@ export default new Vuex.Store({
48
52
. catch ( error => {
49
53
console . log ( 'There was an error:' , error . response )
50
54
} )
55
+ } ,
56
+ fetchEvent ( { commit, getters } , id ) {
57
+ var event = getters . getEventById ( id )
58
+
59
+ if ( event ) {
60
+ commit ( 'SET_EVENT' , event )
61
+ } else {
62
+ EventService . getEvent ( id )
63
+ . then ( response => {
64
+ commit ( 'SET_EVENT' , response . data )
65
+ } )
66
+ . catch ( error => {
67
+ console . log ( 'There was an error:' , error . response )
68
+ } )
69
+ }
51
70
}
52
71
} ,
53
72
getters : {
Original file line number Diff line number Diff line change 25
25
</div >
26
26
</template >
27
27
<script >
28
- import EventService from ' @/services/EventService.js '
28
+ import { mapState } from ' vuex '
29
29
30
30
export default {
31
31
props: [' id' ],
32
- data () {
33
- return {
34
- event : {}
35
- }
36
- },
37
32
created () {
38
- EventService .getEvent (this .id )
39
- .then (response => {
40
- this .event = response .data
41
- })
42
- .catch (error => {
43
- console .log (' There was an error:' , error .response )
44
- })
45
- }
33
+ this .$store .dispatch (' fetchEvent' , this .id )
34
+ },
35
+ computed: mapState ([' event' ])
46
36
}
47
37
</script >
48
38
<style scoped>
You can’t perform that action at this time.
0 commit comments