From 36eeb14a3c6a2a9dbe94da6cf986b41aca42a9cf Mon Sep 17 00:00:00 2001 From: yurj26 <1816387074@qq.com> Date: Fri, 10 Mar 2023 10:43:35 +0800 Subject: [PATCH] fix(h5): setup onError (question/164798) --- packages/uni-h5/src/framework/setup/index.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/uni-h5/src/framework/setup/index.ts b/packages/uni-h5/src/framework/setup/index.ts index 2e29b7e1d2..1b7c0f551c 100644 --- a/packages/uni-h5/src/framework/setup/index.ts +++ b/packages/uni-h5/src/framework/setup/index.ts @@ -157,7 +157,7 @@ export function setupApp(comp: any) { } const onLaunch = () => { injectAppHooks(instance) - const { onLaunch, onShow, onPageNotFound } = instance + const { onLaunch, onShow, onPageNotFound, onError } = instance const path = route.path.slice(1) const launchOptions = initLaunchOptions({ path: path || __uniRoutes[0].meta.route, @@ -178,6 +178,11 @@ export function setupApp(comp: any) { invokeArrayFns(onPageNotFound, pageNotFoundOptions) } } + if (onError) { + instance.appContext.config.errorHandler = (err) => { + invokeArrayFns(onError, err) + } + } } if (__UNI_FEATURE_PAGES__) { // 等待ready后,再onLaunch,否则直达非首页无法获取到正确的path和query -- GitLab