diff --git a/packages/taro-alipay/src/create-component.js b/packages/taro-alipay/src/create-component.js index c0b95e448ed4..aef5e061a225 100644 --- a/packages/taro-alipay/src/create-component.js +++ b/packages/taro-alipay/src/create-component.js @@ -127,7 +127,11 @@ function processEvent (eventHandlerName, obj) { } realArgs = [...datasetArgs, event] } - return scope[eventHandlerName].apply(callScope, realArgs) + if (scope[eventHandlerName]) { + return scope[eventHandlerName].apply(callScope, realArgs) + } else { + throw `事件处理函数${eventHandlerName}不存在` + } } } diff --git a/packages/taro-swan/src/create-component.js b/packages/taro-swan/src/create-component.js index 9a1ec81ea754..f3e7360659f9 100644 --- a/packages/taro-swan/src/create-component.js +++ b/packages/taro-swan/src/create-component.js @@ -144,7 +144,11 @@ function processEvent (eventHandlerName, obj) { } realArgs = [_scope, ...datasetArgs, ...detailArgs, event] } - return scope[eventHandlerName].apply(callScope, realArgs) + if (scope[eventHandlerName]) { + return scope[eventHandlerName].apply(callScope, realArgs) + } else { + throw `事件处理函数${eventHandlerName}不存在` + } } } diff --git a/packages/taro-tt/src/create-component.js b/packages/taro-tt/src/create-component.js index 5831e12c9637..fcdd6890c5b6 100644 --- a/packages/taro-tt/src/create-component.js +++ b/packages/taro-tt/src/create-component.js @@ -147,7 +147,11 @@ function processEvent (eventHandlerName, obj) { } realArgs = [_scope, ...datasetArgs, ...detailArgs, event] } - return scope[eventHandlerName].apply(callScope, realArgs) + if (scope[eventHandlerName]) { + return scope[eventHandlerName].apply(callScope, realArgs) + } else { + throw `事件处理函数${eventHandlerName}不存在` + } } } diff --git a/packages/taro-weapp/src/create-component.js b/packages/taro-weapp/src/create-component.js index b96c29bf66da..92d90cf93c7f 100644 --- a/packages/taro-weapp/src/create-component.js +++ b/packages/taro-weapp/src/create-component.js @@ -176,7 +176,11 @@ function processEvent (eventHandlerName, obj) { } realArgs = [_scope, ...datasetArgs, ...detailArgs, event] } - return scope[eventHandlerName].apply(callScope, realArgs) + if (scope[eventHandlerName]) { + return scope[eventHandlerName].apply(callScope, realArgs) + } else { + throw `事件处理函数${eventHandlerName}不存在` + } } }