feat: 新增初始化函数,全局异步错误捕获功能

This commit is contained in:
奔跑的面条 2023-02-02 20:54:02 +08:00
parent 3a256cbd88
commit 68b8809a1e
3 changed files with 14 additions and 2 deletions

View File

@ -3,7 +3,7 @@ import App from './App.vue'
import router, { setupRouter } from '@/router'
import i18n from '@/i18n/index'
import { setupStore } from '@/store'
import { setupNaive, setupDirectives, setupCustomComponents } from '@/plugins'
import { setupNaive, setupDirectives, setupCustomComponents, initFunction } from '@/plugins'
import { GoAppProvider } from '@/components/GoAppProvider/index'
import { setHtmlTheme } from '@/utils'
@ -53,4 +53,6 @@ async function appInit() {
window['$vue'] = app
}
void appInit()
await appInit()
await initFunction()

View File

@ -2,3 +2,4 @@ export { setupNaive } from '@/plugins/naive'
export { setupDirectives } from '@/plugins/directives'
export { setupCustomComponents } from '@/plugins/customComponents'
export { icon } from '@/plugins/icon'
export { initFunction } from '@/plugins/initFunction'

View File

@ -0,0 +1,9 @@
/**
* *
*/
export const initFunction = async () => {
// 捕获全局错误
window.addEventListener("unhandledrejection", event => {
console.warn(`UNHANDLED PROMISE REJECTION: ${event.reason}`);
});
}