Skip to content

Commit

Permalink
Bugfix
Browse files Browse the repository at this point in the history
Right before navigate out to another route
clears all event handlers, thus avoiding
multiple handlers to be set and the annoying
behaviour of multiple AJAX calls being made.
  • Loading branch information
vedovelli committed Nov 27, 2016
1 parent 41963bf commit da30c7f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
4 changes: 2 additions & 2 deletions client/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ export default {
<style lang="sass" src="assets/sass/app.scss"></style>

<style scoped>
.fade-enter-active {
.fade-enter-active, .fade-leave-active {
transition: opacity .5s ease;
}
.fade-enter {
.fade-enter, .fade-leave-active {
opacity: 0;
}
</style>
23 changes: 16 additions & 7 deletions client/src/modules/categories/main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,19 @@
return this.$route.name === 'categories.new' || this.$route.name === 'categories.edit'
},
},
/**
* Right before navigate out to another route
* clears all event handlers, thus avoiding
* multiple handlers to be set and the annoying
* behaviour of multiple AJAX calls being made.
*/
beforeRouteLeave(to, from, next) {
this.$bus.$off('navigate')
this.$bus.$off('category.created')
this.$bus.$off('category.updated')
jQuery('body').off('keyup')
next()
},
mounted() {
/**
* Listen to pagination navigate event
Expand All @@ -172,15 +185,11 @@
*/
this.$bus.$on('category.created', () => this.fetch())
this.$bus.$on('category.updated', () => this.fetch())
/**
* We only fetch data the first time
* component is mounted. We can set
* up a timer to fetch new data
* from time to time
* Fetch data immediately after component is mounted
*/
if (this.pager.data === undefined) {
this.fetch()
}
this.fetch()
},
/**
* This hook is called every time DOM
Expand Down

0 comments on commit da30c7f

Please sign in to comment.