提交 3226634c 编写于 作者: Q qiang

fix: 小程序(微信、QQ v-for 支持遍历对象表达式 fixed #449

上级 8dc528a7
......@@ -120,4 +120,15 @@ describe('mp:compiler-mp-weixin', () => {
'<view><slot-comp generic:scoped-slots-test="test-slot-comp-test" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[\'test\']}}"></slot-comp><slot-comp generic:scoped-slots-test="test-slot-comp-test1" vue-id="551070e6-2" bind:__l="__l" vue-slots="{{[\'test\']}}"></slot-comp><slot-comp generic:scoped-slots-test="test-slot-comp-test2" vue-id="551070e6-3" bind:__l="__l" vue-slots="{{[\'test\']}}"></slot-comp><slot-comp generic:scoped-slots-test="test-slot-comp-test3" vue-id="551070e6-4" bind:__l="__l" vue-slots="{{[\'test\']}}"></slot-comp></view>'
)
})
it('generate ObjectExpression', () => {
assertCodegen(
'<view v-for="(item,key) in {x:0}" :key="key">{{item}}</view>',
'<block wx:for="{{({x:0})}}" wx:for-item="item" wx:for-index="key" wx:key="key"><view>{{item}}</view></block>'
)
assertCodegen(
'<template v-for="(item, key) in { list1, list2 }"></template>',
'<block wx:for="{{({list1,list2})}}" wx:for-item="item" wx:for-index="key"></block>'
)
})
})
......@@ -105,7 +105,10 @@ function genElement (ast, state, isRoot = false) {
if (ast.attr[name] === '' && name !== 'value') { // value属性需要保留=''
return name
}
return `${name}="${ast.attr[name]}"`
let value = ast.attr[name]
// 微信和QQ小程序解析 {{{}}} 报错,需要使用()包裹
value = value.replace(/(\{\{)(\{.+?\})(\}\})/, '$1($2)$3')
return `${name}="${value}"`
})
.join(' ')
: ''
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册