提交 cd3c3e53 编写于 作者: fxy060608's avatar fxy060608

fix: handle lifecycle hook error

上级 e4f443b1
......@@ -1067,13 +1067,6 @@ var serviceContext = (function (vue) {
function cacheStringFunction(fn) {
return cache(fn);
}
const invokeArrayFns = (fns, arg) => {
let ret;
for (let i = 0; i < fns.length; i++) {
ret = fns[i](arg);
}
return ret;
};
function once(fn, ctx = null) {
let res;
return ((...args) => {
......@@ -1874,7 +1867,14 @@ var serviceContext = (function (vue) {
}
}
const hooks = vm.$[name];
return hooks && invokeArrayFns(hooks, args);
if (!hooks) {
return;
}
let ret;
for (let i = 0; i < hooks.length; i++) {
ret = vue.callWithErrorHandling(hooks[i], vm.$, name, [args]);
}
return ret;
}
function normalizeRoute(toRoute) {
......
import { ComponentPublicInstance } from 'vue'
import { callWithErrorHandling, ComponentPublicInstance } from 'vue'
import { isString } from '@vue/shared'
import { invokeArrayFns } from '@dcloudio/uni-shared'
import { getCurrentPageVm } from './page'
export function invokeHook(name: string, args?: unknown): unknown
......@@ -37,7 +36,14 @@ export function invokeHook(
}
}
const hooks = vm.$[name as string]
return hooks && invokeArrayFns(hooks, args)
if (!hooks) {
return
}
let ret
for (let i = 0; i < hooks.length; i++) {
ret = callWithErrorHandling(hooks[i], vm.$, name as any, [args])
}
return ret
}
export function hasHook(vm: ComponentPublicInstance | number, name: string) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册