Skip to content

Commit a68413c

Browse files
committed
refactor[errorLog]: save the logs in vuex
1 parent f9aaaa9 commit a68413c

File tree

6 files changed

+34
-31
lines changed

6 files changed

+34
-31
lines changed

src/errorLog.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import Vue from 'vue'
2-
import errLog from '@/store/errorLog'
2+
import store from './store'
33

44
// you can set only in production env show the error-log
55
// if (process.env.NODE_ENV === 'production') {
6-
Vue.config.errorHandler = function(err, vm, info) {
7-
errLog.pushLog({
8-
err,
9-
vm,
10-
info,
11-
url: window.location.href
6+
Vue.config.errorHandler = function(err, vm, info, a) {
7+
Vue.nextTick(() => {
8+
store.dispatch('addErrorLog', {
9+
err,
10+
vm,
11+
info,
12+
url: window.location.href
13+
})
14+
console.error(err, info)
1215
})
13-
console.error(err, info)
1416
}
1517
// }

src/store/errorLog.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/store/getters.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const getters = {
1111
roles: state => state.user.roles,
1212
setting: state => state.user.setting,
1313
permission_routers: state => state.permission.routers,
14-
addRouters: state => state.permission.addRouters
14+
addRouters: state => state.permission.addRouters,
15+
errorLogs: state => state.errorLog.logs
1516
}
1617
export default getters

src/store/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Vue from 'vue'
22
import Vuex from 'vuex'
33
import app from './modules/app'
4+
import errorLog from './modules/errorLog'
45
import permission from './modules/permission'
56
import tagsView from './modules/tagsView'
67
import user from './modules/user'
@@ -11,6 +12,7 @@ Vue.use(Vuex)
1112
const store = new Vuex.Store({
1213
modules: {
1314
app,
15+
errorLog,
1416
permission,
1517
tagsView,
1618
user

src/store/modules/errorLog.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const errorLog = {
2+
state: {
3+
logs: []
4+
},
5+
mutations: {
6+
ADD_ERROR_LOG: (state, log) => {
7+
state.logs.push(log)
8+
}
9+
},
10+
actions: {
11+
addErrorLog({ commit }, log) {
12+
commit('ADD_ERROR_LOG', log)
13+
}
14+
}
15+
}
16+
17+
export default errorLog

src/views/layout/components/Navbar.vue

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
<breadcrumb class="breadcrumb-container"></breadcrumb>
66

77
<div class="right-menu">
8-
9-
<error-log v-if="log.length>0" class="errLog-container right-menu-item" :logsList="log"></error-log>
8+
<error-log v-if="errorLogs.length>0" class="errLog-container right-menu-item" :logsList="errorLogs"></error-log>
109

1110
<el-tooltip effect="dark" content="全屏" placement="bottom">
1211
<screenfull class="screenfull right-menu-item"></screenfull>
@@ -58,7 +57,6 @@ import Hamburger from '@/components/Hamburger'
5857
import ThemePicker from '@/components/ThemePicker'
5958
import Screenfull from '@/components/Screenfull'
6059
import ErrorLog from '@/components/ErrorLog'
61-
import errLogStore from '@/store/errorLog'
6260
6361
export default {
6462
components: {
@@ -68,17 +66,13 @@ export default {
6866
ErrorLog,
6967
Screenfull
7068
},
71-
data() {
72-
return {
73-
log: errLogStore.state.errLog
74-
}
75-
},
7669
computed: {
7770
...mapGetters([
7871
'sidebar',
7972
'name',
8073
'avatar',
81-
'language'
74+
'language',
75+
'errorLogs'
8276
])
8377
},
8478
methods: {

0 commit comments

Comments
 (0)