提交 d854dc9d 编写于 作者: Q qiang

fix: 解决支付宝小程序平台v-for部分情况key无效的问题

上级 779f5647
......@@ -18,7 +18,7 @@ describe('mp:compiler-mp-alipay', () => {
it('generate v-for directive', () => {
assertCodegen(
'<view><view v-for="(item,index) in items" :key="index"></view></view>',
'<view><block a:for="{{items}}" a:for-item="item" a:for-index="index" a:key="index"><view></view></block></view>'
'<view><view a:for="{{items}}" a:for-item="item" a:for-index="index" a:key="index"></view></view>'
)
})
......@@ -39,11 +39,11 @@ describe('mp:compiler-mp-alipay', () => {
)
assertCodegen(
'<component1 v-for="item in items" ref="c3"></component1>',
'<block a:for="{{items}}" a:for-item="item" a:for-index="__i0__"><component1 vue-id="{{\'551070e6-1-\'+__i0__}}" ref="__r" data-ref-in-for="c3" onVueInit="__l"></component1></block>'
'<component1 vue-id="{{\'551070e6-1-\'+__i0__}}" ref="__r" data-ref-in-for="c3" a:for="{{items}}" a:for-item="item" a:for-index="__i0__" onVueInit="__l"></component1>'
)
assertCodegen(
'<component1 v-for="item in items" :ref="c4"></component1>',
'<block a:for="{{items}}" a:for-item="item" a:for-index="__i0__"><component1 vue-id="{{\'551070e6-1-\'+__i0__}}" ref="__r" data-ref-in-for="{{c4}}" onVueInit="__l"></component1></block>'
'<component1 vue-id="{{\'551070e6-1-\'+__i0__}}" ref="__r" data-ref-in-for="{{c4}}" a:for="{{items}}" a:for-item="item" a:for-index="__i0__" onVueInit="__l"></component1>'
)
})
it('generate default slot', () => {
......
......@@ -399,10 +399,17 @@ function traverseRenderList (callExprNode, state) {
}
}
const children = traverseExpr(forReturnStatementArgument, state)
// 支付宝小程序在 block 标签上使用 key 时顺序不能保障
if (state.options.platform.name === 'mp-alipay' && t.isCallExpression(forReturnStatementArgument) && children && children.type) {
children.attr = children.attr || {}
Object.assign(children.attr, attr)
return children
}
return {
type: 'block',
attr,
children: normalizeChildren(traverseExpr(forReturnStatementArgument, state))
children: normalizeChildren(children)
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册