Skip to content

Commit aa980a3

Browse files
committed
Using In-Component Route Guard
1 parent b856043 commit aa980a3

File tree

5 files changed

+18
-6
lines changed

5 files changed

+18
-6
lines changed

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"dependencies": {
1111
"axios": "^0.18.0",
1212
"lodash": "^4.17.11",
13+
"nprogress": "^0.2.0",
1314
"vue": "^2.5.17",
1415
"vue-router": "^3.0.1",
1516
"vuejs-datepicker": "^1.5.3",

src/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import App from './App.vue'
55
import router from './router'
66
import store from './store/store'
77
import BaseIcon from '@/components/BaseIcon'
8+
import 'nprogress/nprogress.css'
89

910
Vue.component('BaseIcon', BaseIcon)
1011

src/store/modules/event.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export const actions = {
6363
if (event) {
6464
commit('SET_EVENT', event)
6565
} else {
66-
EventService.getEvent(id)
66+
return EventService.getEvent(id)
6767
.then(response => {
6868
commit('SET_EVENT', response.data)
6969
})

src/views/EventShow.vue

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,22 @@
2525
</div>
2626
</template>
2727
<script>
28-
import { mapState, mapActions } from 'vuex'
28+
import { mapState } from 'vuex'
29+
import NProgress from 'nprogress'
30+
import store from '@/store/store'
2931
3032
export default {
3133
props: ['id'],
32-
created() {
33-
this.fetchEvent(this.id)
34+
beforeRouteEnter(routeTo, routeFrom, next) {
35+
NProgress.start()
36+
store.dispatch('event/fetchEvent', routeTo.params.id).then(() => {
37+
NProgress.done()
38+
next()
39+
})
3440
},
3541
computed: mapState({
3642
event: state => state.event.event
37-
}),
38-
methods: mapActions('event', ['fetchEvent'])
43+
})
3944
}
4045
</script>
4146
<style scoped>

0 commit comments

Comments
 (0)