新增全局错误监听
This commit is contained in:
14
src/main.js
14
src/main.js
@@ -60,6 +60,18 @@ const app = createApp(App)
|
|||||||
app.config.globalProperties.$copy = function (text) {
|
app.config.globalProperties.$copy = function (text) {
|
||||||
copy(text, this);
|
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);
|
||||||
|
}
|
||||||
|
};
|
||||||
app.config.warnHandler = () => null;
|
app.config.warnHandler = () => null;
|
||||||
app.use(store).use(router).use(components).use(VueClipboard).mount('#app')
|
app.use(store).use(router).use(components).use(VueClipboard).mount('#app')
|
||||||
|
Reference in New Issue
Block a user