error.js 1.3 KB
Newer Older
M
MicroMilo 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
import store from '@/store'
import config from '@/admin.config.js'

// #ifndef VUE3
export function initError(Vue) {
     const debugOptions = config.navBar.debug
     if (debugOptions && debugOptions.enable === true) {
        const oldErrorHandler = Vue.config.errorHandler
        Vue.config.errorHandler = function errorHandler(err, vm, info) {
			console.error(err)
             const route = vm.$page && vm.$page.route
             store.dispatch('error/add', {
                 err: err.toString(),
				 info,
                 route,
                 time: new Date().toLocaleTimeString()
             })
            return oldErrorHandler(err, vm, info)
         }
     }
}
// #endif

// #ifdef VUE3
export function initError(app) {
    const debugOptions = config.navBar.debug
    if (debugOptions && debugOptions.enable === true) {
        const oldErrorHandler = app.config.errorHandler
        app.config.errorHandler = function errorHandler(err, vm, info) {
			console.error(err)
            const route = vm.$page && vm.$page.route
            store.dispatch('error/add', {
                err: err.toString(),
                info,
                route,
                time: new Date().toLocaleTimeString()
            })
            return oldErrorHandler && oldErrorHandler(err, vm, info)
        }
    }
}
// #endif