From 27af66caa868c8a6e8d4098579cb84a09412b14f Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Mon, 4 Jul 2022 14:25:22 +0800 Subject: [PATCH] fix(mp-weixin): event key (#3677) --- packages/uni-mp-compiler/src/transforms/vOn.ts | 4 ++-- packages/uni-mp-weixin/__tests__/vOn.spec.ts | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/uni-mp-compiler/src/transforms/vOn.ts b/packages/uni-mp-compiler/src/transforms/vOn.ts index e605b9da1..1de5b9fbf 100644 --- a/packages/uni-mp-compiler/src/transforms/vOn.ts +++ b/packages/uni-mp-compiler/src/transforms/vOn.ts @@ -213,10 +213,10 @@ export function wrapperVOn( const keys: string[] = [] if (context.miniProgram.event?.key && context.inVFor) { const keyProp = findProp(node, 'key') - // 仅对 v-for 中 item.id 类型做处理,使用索引无需处理,避免引发更多问题 + // 对 for 中的所有事件增加 key 标记,避免微信小程序不更新事件对象 if (keyProp && isDirectiveNode(keyProp) && keyProp.exp) { const keyCode = genExpr(keyProp.exp) - if (keyCode && keyCode.includes('.')) { + if (keyCode) { keys.push(',') keys.push(genExpr(keyProp.exp)) } diff --git a/packages/uni-mp-weixin/__tests__/vOn.spec.ts b/packages/uni-mp-weixin/__tests__/vOn.spec.ts index 15ab422fb..c419b536c 100644 --- a/packages/uni-mp-weixin/__tests__/vOn.spec.ts +++ b/packages/uni-mp-weixin/__tests__/vOn.spec.ts @@ -36,7 +36,14 @@ describe('mp-weixin: transform v-on', () => { ``, ``, `(_ctx, _cache) => { - return { a: _f(_ctx.items, (item, index, i0) => { return { a: index, b: _o($event => _ctx.test(item)) }; }) } + return { a: _f(_ctx.items, (item, index, i0) => { return { a: index, b: _o($event => _ctx.test(item), index) }; }) } +}` + ) + assert( + ``, + ``, + `(_ctx, _cache) => { + return { a: _f(_ctx.items, (item, k0, i0) => { return { a: item, b: _o($event => _ctx.test(item), item) }; }) } }` ) }) -- GitLab