ADD 错误异常捕捉
This commit is contained in:
parent
5dd5ad72ab
commit
c1a5786cd0
|
|
@ -33,9 +33,6 @@ app.use(store);
|
|||
app.use(router);
|
||||
app.use(ElementPlus, {size: 'small', locale: locale});
|
||||
|
||||
//全局代码错误捕捉
|
||||
app.config.errorHandler = errorHandler
|
||||
|
||||
//注册全局组件
|
||||
app.component('scTable', scTable);
|
||||
app.component('scFilterBar', scFilterBar);
|
||||
|
|
@ -47,5 +44,8 @@ app.component('scTableSelect', scTableSelect);
|
|||
//注册全局指令
|
||||
app.directive('auth', auth)
|
||||
|
||||
//全局代码错误捕捉
|
||||
app.config.errorHandler = errorHandler
|
||||
|
||||
//挂载app
|
||||
app.mount('#app');
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
/**
|
||||
* 全局代码错误捕捉
|
||||
* 比如split一个null 就会被捕捉到
|
||||
* 比如 null.length 就会被捕捉到
|
||||
*/
|
||||
import { ElNotification } from 'element-plus';
|
||||
|
||||
export default (error)=>{
|
||||
|
||||
export default (error, vm)=>{
|
||||
var errorMap = {
|
||||
InternalError: "Javascript引擎内部错误",
|
||||
ReferenceError: "未找到对象",
|
||||
|
|
@ -17,11 +15,14 @@ export default (error)=>{
|
|||
}
|
||||
var errorName = errorMap[error.name] || "未知错误"
|
||||
|
||||
ElNotification.error({
|
||||
title: errorName,
|
||||
message: error
|
||||
});
|
||||
|
||||
console.warn('[SCUI]: 捕捉到错误');
|
||||
console.warn(`[SCUI error]: ${error}`);
|
||||
console.error(error);
|
||||
//throw error;
|
||||
|
||||
vm.$nextTick(() => {
|
||||
vm.$notify.error({
|
||||
title: errorName,
|
||||
message: error
|
||||
});
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,64 @@
|
|||
<!--
|
||||
* @Descripttion: 模拟触发错误
|
||||
* @version: 1.0
|
||||
* @Author: sakuya
|
||||
* @Date: 2021年6月25日08:53:13
|
||||
* @LastEditors:
|
||||
* @LastEditTime:
|
||||
-->
|
||||
|
||||
<template>
|
||||
<el-main>
|
||||
<el-alert title="通过VUE开放的errorHandler可以很方便的捕捉到处理异常, SCUI收集后可上报日志收集系统, 相关代码:@/utils/errorHandler.js" type="success" style="margin-bottom:20px;"></el-alert>
|
||||
<el-row :gutter="15">
|
||||
<el-col :lg="8">
|
||||
<el-card shadow="never" header="ReferenceError">
|
||||
<el-button type="danger" @click="ReferenceError">模拟触发</el-button>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :lg="8">
|
||||
<el-card shadow="never" header="TypeError">
|
||||
<el-button type="danger" @click="TypeError">模拟触发</el-button>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :lg="8">
|
||||
<el-card shadow="never" header="RangeError">
|
||||
<el-button type="danger" @click="RangeError">模拟触发</el-button>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-alert title=":) 尝试模拟SyntaxError语法错误时,发现VUE编译失败,所以这不作模拟了" type="info" style="margin-top:20px;"></el-alert>
|
||||
</el-main>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
/* eslint-disable */
|
||||
//为了演示异常,跳过eslint
|
||||
export default {
|
||||
name: 'codebug',
|
||||
data() {
|
||||
return {
|
||||
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
|
||||
},
|
||||
methods: {
|
||||
ReferenceError(){
|
||||
console.log(obj);
|
||||
},
|
||||
TypeError(){
|
||||
const obj = null
|
||||
console.log(obj.a);
|
||||
},
|
||||
RangeError(){
|
||||
const n = 1
|
||||
n.toFixed(101)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
</style>
|
||||
Loading…
Reference in New Issue