提交 27af66ca 编写于 作者: fxy060608's avatar fxy060608

fix(mp-weixin): event key (#3677)

上级 b529181c
......@@ -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))
}
......
......@@ -36,7 +36,14 @@ describe('mp-weixin: transform v-on', () => {
`<view v-for="(item,index) in items" :key="index" @click="test(item)"/>`,
`<view wx:for="{{a}}" wx:for-item="item" wx:key="a" bindtap="{{item.b}}"/>`,
`(_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(
`<view v-for="item in items" :key="item" @click="test(item)"/>`,
`<view wx:for="{{a}}" wx:for-item="item" wx:key="a" bindtap="{{item.b}}"/>`,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: item, b: _o($event => _ctx.test(item), item) }; }) }
}`
)
})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册