From 2b5e77960cce541ebb36626dc1a2e7bcf37e8a83 Mon Sep 17 00:00:00 2001 From: qiang Date: Fri, 2 Sep 2022 16:35:59 +0800 Subject: [PATCH] =?UTF-8?q?fix(mp):=20=E5=B0=8F=E7=A8=8B=E5=BA=8F=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E5=86=85=E9=83=A8=E6=94=AF=E6=8C=81=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=20kebab-case=20=E4=BA=8B=E4=BB=B6=E5=90=8D=20#1802?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/platforms/mp-weixin/runtime/index.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/platforms/mp-weixin/runtime/index.js b/src/platforms/mp-weixin/runtime/index.js index ed11b5f93..4012f0b42 100644 --- a/src/platforms/mp-weixin/runtime/index.js +++ b/src/platforms/mp-weixin/runtime/index.js @@ -15,7 +15,17 @@ const customize = cached((str) => { function initTriggerEvent (mpInstance) { const oldTriggerEvent = mpInstance.triggerEvent const newTriggerEvent = function (event, ...args) { - return oldTriggerEvent.apply(mpInstance, [customize(event), ...args]) + // 事件名统一转驼峰格式,仅处理:当前组件为 vue 组件、当前组件为 vue 组件子组件 + if (this.$vm || (this.dataset && this.dataset.comType)) { + event = customize(event) + } else if (__PLATFORM__ === 'mp-weixin' || __PLATFORM__ === 'mp-qq') { + // 针对微信/QQ小程序单独补充驼峰格式事件,以兼容历史项目 + const newEvent = customize(event) + if (newEvent !== event) { + oldTriggerEvent.apply(this, [newEvent, ...args]) + } + } + return oldTriggerEvent.apply(this, [event, ...args]) } try { // 京东小程序 triggerEvent 为只读 -- GitLab