Skip to content

Commit da30c7f

Browse files
committed
Bugfix
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.
1 parent 41963bf commit da30c7f

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

client/src/App.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ export default {
3131
<style lang="sass" src="assets/sass/app.scss"></style>
3232

3333
<style scoped>
34-
.fade-enter-active {
34+
.fade-enter-active, .fade-leave-active {
3535
transition: opacity .5s ease;
3636
}
37-
.fade-enter {
37+
.fade-enter, .fade-leave-active {
3838
opacity: 0;
3939
}
4040
</style>

client/src/modules/categories/main.vue

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,19 @@
162162
return this.$route.name === 'categories.new' || this.$route.name === 'categories.edit'
163163
},
164164
},
165+
/**
166+
* Right before navigate out to another route
167+
* clears all event handlers, thus avoiding
168+
* multiple handlers to be set and the annoying
169+
* behaviour of multiple AJAX calls being made.
170+
*/
171+
beforeRouteLeave(to, from, next) {
172+
this.$bus.$off('navigate')
173+
this.$bus.$off('category.created')
174+
this.$bus.$off('category.updated')
175+
jQuery('body').off('keyup')
176+
next()
177+
},
165178
mounted() {
166179
/**
167180
* Listen to pagination navigate event
@@ -172,15 +185,11 @@
172185
*/
173186
this.$bus.$on('category.created', () => this.fetch())
174187
this.$bus.$on('category.updated', () => this.fetch())
188+
175189
/**
176-
* We only fetch data the first time
177-
* component is mounted. We can set
178-
* up a timer to fetch new data
179-
* from time to time
190+
* Fetch data immediately after component is mounted
180191
*/
181-
if (this.pager.data === undefined) {
182-
this.fetch()
183-
}
192+
this.fetch()
184193
},
185194
/**
186195
* This hook is called every time DOM

0 commit comments

Comments
 (0)