提交 587b29e4 编写于 作者: Q qiang

fix(mp): 修复 v-for 缺少 key 时会使用作用域插槽 key 的问题

上级 d4acf986
......@@ -279,6 +279,10 @@ describe('mp:compiler-extra', () => {
'<view v-for="item in dataList" :key="item.id" @click="click1(item, 1);click2(item, 2);"/>',
'<block wx:for="{{dataList}}" wx:for-item="item" wx:for-index="__i0__" wx:key="id"><view data-event-opts="{{[[\'tap\',[[\'click1\',[\'$0\',1],[[[\'dataList\',\'id\',item.id]]]],[\'click2\',[\'$0\',2],[[[\'dataList\',\'id\',item.id]]]]]]]}}" bindtap="__e"></view></block>'
)
assertCodegen(
'<custom-view v-for="(item,index) in dataList" @test="test($event, item)"><template v-slot><view>text</view></template></custom-view>',
'<block wx:for="{{dataList}}" wx:for-item="item" wx:for-index="index"><custom-view bind:test="__e" vue-id="{{\'551070e6-1-\'+index}}" data-event-opts="{{[[\'^test\',[[\'test\',[\'$event\',\'$0\'],[[[\'dataList\',\'\',index]]]]]]]}}" bind:__l="__l" vue-slots="{{[\'default\']}}"><view>text</view></custom-view></block>'
)
// TODO vue的数字 item 是从1,小程序是从0,后续考虑抹平差异
assertCodegen(
'<view>1<view v-for="item in items" :key="item"><input v-for="item1 in item" :key="item1" @input="handle" @click="e=>count++"></view></view>',
......
......@@ -4,7 +4,8 @@ const babelGenerate = require('@babel/generator').default
const uniI18n = require('@dcloudio/uni-cli-i18n')
const {
METHOD_RENDER_LIST
METHOD_RENDER_LIST,
METHOD_RESOLVE_SCOPED_SLOTS
} = require('./constants')
function cached (fn) {
......@@ -48,6 +49,8 @@ function traverseKey (ast, state) {
CallExpression (path) {
if (path.node.callee.name === METHOD_RENDER_LIST) {
path.stop()
} else if (path.node.callee.name === METHOD_RESOLVE_SCOPED_SLOTS) {
path.skip()
}
}
})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册