refactor[errorLog]: save the logs in vuex
This commit is contained in:
parent
f9aaaa9091
commit
a68413cb8f
|
@ -1,15 +1,17 @@
|
|||
import Vue from 'vue'
|
||||
import errLog from '@/store/errorLog'
|
||||
import store from './store'
|
||||
|
||||
// you can set only in production env show the error-log
|
||||
// if (process.env.NODE_ENV === 'production') {
|
||||
Vue.config.errorHandler = function(err, vm, info) {
|
||||
errLog.pushLog({
|
||||
err,
|
||||
vm,
|
||||
info,
|
||||
url: window.location.href
|
||||
Vue.config.errorHandler = function(err, vm, info, a) {
|
||||
Vue.nextTick(() => {
|
||||
store.dispatch('addErrorLog', {
|
||||
err,
|
||||
vm,
|
||||
info,
|
||||
url: window.location.href
|
||||
})
|
||||
console.error(err, info)
|
||||
})
|
||||
console.error(err, info)
|
||||
}
|
||||
// }
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
const errLog = {
|
||||
state: {
|
||||
errLog: []
|
||||
},
|
||||
pushLog(log) {
|
||||
this.state.errLog.unshift(log)
|
||||
},
|
||||
clearLog() {
|
||||
this.state.errLog = []
|
||||
}
|
||||
}
|
||||
|
||||
export default errLog
|
|
@ -11,6 +11,7 @@ const getters = {
|
|||
roles: state => state.user.roles,
|
||||
setting: state => state.user.setting,
|
||||
permission_routers: state => state.permission.routers,
|
||||
addRouters: state => state.permission.addRouters
|
||||
addRouters: state => state.permission.addRouters,
|
||||
errorLogs: state => state.errorLog.logs
|
||||
}
|
||||
export default getters
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
import app from './modules/app'
|
||||
import errorLog from './modules/errorLog'
|
||||
import permission from './modules/permission'
|
||||
import tagsView from './modules/tagsView'
|
||||
import user from './modules/user'
|
||||
|
@ -11,6 +12,7 @@ Vue.use(Vuex)
|
|||
const store = new Vuex.Store({
|
||||
modules: {
|
||||
app,
|
||||
errorLog,
|
||||
permission,
|
||||
tagsView,
|
||||
user
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
const errorLog = {
|
||||
state: {
|
||||
logs: []
|
||||
},
|
||||
mutations: {
|
||||
ADD_ERROR_LOG: (state, log) => {
|
||||
state.logs.push(log)
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
addErrorLog({ commit }, log) {
|
||||
commit('ADD_ERROR_LOG', log)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default errorLog
|
|
@ -5,8 +5,7 @@
|
|||
<breadcrumb class="breadcrumb-container"></breadcrumb>
|
||||
|
||||
<div class="right-menu">
|
||||
|
||||
<error-log v-if="log.length>0" class="errLog-container right-menu-item" :logsList="log"></error-log>
|
||||
<error-log v-if="errorLogs.length>0" class="errLog-container right-menu-item" :logsList="errorLogs"></error-log>
|
||||
|
||||
<el-tooltip effect="dark" content="全屏" placement="bottom">
|
||||
<screenfull class="screenfull right-menu-item"></screenfull>
|
||||
|
@ -58,7 +57,6 @@ import Hamburger from '@/components/Hamburger'
|
|||
import ThemePicker from '@/components/ThemePicker'
|
||||
import Screenfull from '@/components/Screenfull'
|
||||
import ErrorLog from '@/components/ErrorLog'
|
||||
import errLogStore from '@/store/errorLog'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
|
@ -68,17 +66,13 @@ export default {
|
|||
ErrorLog,
|
||||
Screenfull
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
log: errLogStore.state.errLog
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
...mapGetters([
|
||||
'sidebar',
|
||||
'name',
|
||||
'avatar',
|
||||
'language'
|
||||
'language',
|
||||
'errorLogs'
|
||||
])
|
||||
},
|
||||
methods: {
|
||||
|
|
Loading…
Reference in New Issue