重新定义全局报错异常
This commit is contained in:
21
src/main.js
21
src/main.js
@@ -61,17 +61,16 @@ app.config.globalProperties.$copy = function (text) {
|
||||
copy(text, this);
|
||||
};
|
||||
// 全局错误处理
|
||||
app.config.errorHandler = (err, vm, info) => {
|
||||
console.log(err)
|
||||
// 判断错误类型,如果是 TypeError 且错误信息包含 'insertBefore',则处理该错误
|
||||
if (err instanceof TypeError && err.message.includes('insertBefore')) {
|
||||
console.error('捕获到 TypeError 错误:', err);
|
||||
window.location.reload();
|
||||
// 你可以在这里执行额外的错误处理逻辑,如显示提示消息等
|
||||
} else {
|
||||
// 其他类型的错误,可以选择打印到控制台
|
||||
console.error('捕获到其他类型的错误:', err);
|
||||
window.onerror = function (message, source, lineno, colno, error) {
|
||||
console.log(error)
|
||||
// 判断是否是 'insertBefore' 错误
|
||||
if (error instanceof TypeError && message.includes('insertBefore')) {
|
||||
console.error('捕获到 TypeError 错误:', error);
|
||||
window.location.reload();
|
||||
// 你可以在这里处理错误,比如记录日志或执行其他操作
|
||||
return true; // 阻止浏览器默认的错误处理
|
||||
}
|
||||
};
|
||||
return false; // 默认处理其他类型的错误
|
||||
};
|
||||
app.config.warnHandler = () => null;
|
||||
app.use(store).use(router).use(components).use(VueClipboard).mount('#app')
|
||||
|
Reference in New Issue
Block a user