From 3e3c789b7643ab5c7f0ccf5a24830bf70d3bddd2 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Mon, 24 Aug 2020 00:53:18 +0800 Subject: [PATCH] pref: stop refresh statistics when catch error (#233) * 1.3.0-beta.2 * fix: token expire. * pref: when an error occurs in the request, stop request statistics api. --- src/views/dashboard/Dashboard.vue | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/views/dashboard/Dashboard.vue b/src/views/dashboard/Dashboard.vue index 460d864e..3452f9d4 100644 --- a/src/views/dashboard/Dashboard.vue +++ b/src/views/dashboard/Dashboard.vue @@ -300,14 +300,14 @@ export default { interval: null } }, - created() { + beforeMount() { this.handleLoadStatistics() this.handleListLatestPosts() this.handleListLatestLogs() }, computed: { formattedLogDatas() { - return this.latestLogs.map(log => { + return this.latestLogs.map((log) => { log.type = this.logTypes[log.type].text return log }) @@ -319,7 +319,7 @@ export default { } }, beforeRouteEnter(to, from, next) { - next(vm => { + next((vm) => { vm.interval = setInterval(() => { vm.handleLoadStatistics() }, 5000) @@ -341,7 +341,7 @@ export default { this.activityLoading = true postApi .listLatest(5) - .then(response => { + .then((response) => { this.latestPosts = response.data.data }) .finally(() => { @@ -354,7 +354,7 @@ export default { this.logLoading = true logApi .listLatest(5) - .then(response => { + .then((response) => { this.latestLogs = response.data.data }) .finally(() => { @@ -366,9 +366,12 @@ export default { handleLoadStatistics() { statisticsApi .statistics() - .then(response => { + .then((response) => { this.statisticsData = response.data.data }) + .catch(() => { + clearInterval(this.interval) + }) .finally(() => { setTimeout(() => { this.statisticsLoading = false @@ -376,7 +379,7 @@ export default { }) }, handlePostPreview(postId) { - postApi.preview(postId).then(response => { + postApi.preview(postId).then((response) => { window.open(response.data, '_blank') }) },