diff --git a/packages/cli/core/plugins/template/directives/v-on.js b/packages/cli/core/plugins/template/directives/v-on.js index 65c7af8c6..1bf399ec0 100644 --- a/packages/cli/core/plugins/template/directives/v-on.js +++ b/packages/cli/core/plugins/template/directives/v-on.js @@ -10,12 +10,11 @@ const parseHandlerProxy = (expr, scope) => { let injectParams = []; let handlerExpr = expr; - let functionName = 'proxyHandler'; + let eventInArg = false; if (/^\w+$/.test(expr)) { // @tap="doSomething" - injectParams.push('$event'); handlerExpr += '($event)'; - functionName = 'proxyHandlerWithEvent'; + eventInArg = true; } else { let identifiers; try { @@ -37,13 +36,13 @@ const parseHandlerProxy = (expr, scope) => { } if (identifiers.$event) { - injectParams.push('$event'); - functionName = 'proxyHandlerWithEvent'; + eventInArg = true; } } - let proxy = `function ${functionName} (${injectParams.join(', ')}) { + let proxy = `function proxy (${injectParams.join(', ')}) { + ${eventInArg ? 'let $event = arguments[arguments.length - 1];' : ''} with (this) { return (function () { ${handlerExpr} diff --git a/packages/core/weapp/init/methods.js b/packages/core/weapp/init/methods.js index ddee77756..aca62bbd0 100644 --- a/packages/core/weapp/init/methods.js +++ b/packages/core/weapp/init/methods.js @@ -75,11 +75,7 @@ const proxyHandler = function (e) { let $event = new Event(e); if (isFunc(fn)) { - if (fn.name === 'proxyHandlerWithEvent') { - return fn.apply(vm, params.concat($event)); - } else { - return fn.apply(vm, params); - } + return fn.apply(vm, params.concat($event)); } else if (!model) { throw new Error('Unrecognized event'); }