From d21c8f26cb9e11e9b9a331bcf5ff306b4ced4479 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Mon, 20 Jun 2022 11:47:46 +0800 Subject: [PATCH] fix(mp): kebab-case event (#3616) --- packages/uni-mp-core/src/runtime/util.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/uni-mp-core/src/runtime/util.ts b/packages/uni-mp-core/src/runtime/util.ts index ce3e4111b..16405b09d 100644 --- a/packages/uni-mp-core/src/runtime/util.ts +++ b/packages/uni-mp-core/src/runtime/util.ts @@ -1,4 +1,4 @@ -import { hasOwn, isArray } from '@vue/shared' +import { hasOwn, isArray, hyphenate } from '@vue/shared' import { ComponentOptions, ComponentInternalInstance, @@ -142,17 +142,20 @@ export function handleEvent( // 快手小程序的 __l 方法也会走此处逻辑,但没有 __ins__ if (__ins__) { // 自定义事件,通过 triggerEvent 传递 __ins__ - methodName = (__ins__.properties[EVENT_OPTS] || {})[type] + methodName = resolveMethodName(type, __ins__.properties[EVENT_OPTS] || {}) } else if (dataset && dataset[EVENT_OPTS]) { // 快手小程序 input 等内置组件的 input 事件也会走此逻辑,所以从 dataset 中读取 - methodName = dataset[EVENT_OPTS][type] + methodName = resolveMethodName(type, dataset[EVENT_OPTS]) } - if (!(this as any)[methodName]) { return console.warn(type + ' not found') } ;(this as any)[methodName](event) } + +function resolveMethodName(name: string, obj: Record) { + return obj[name] || obj[hyphenate(name)] +} /** * @param properties */ -- GitLab