提交 647a7831 编写于 作者: fxy060608's avatar fxy060608

fix(mp-weixin): add for-index when for-item='index' (#3193)

上级 c6d5de7e
......@@ -32,7 +32,14 @@ describe(`compiler: v-for`, () => {
test(`number expression`, () => {
assert(
`<view v-for="index in 5" />`,
`<view wx:for="{{a}}" wx:for-item="index"/>`,
`<view wx:for="{{a}}" wx:for-item="index" wx:for-index="i0"/>`,
`(_ctx, _cache) => {
return { a: _f(5, (index, k0, i0) => { return {}; }) }
}`
)
assert(
`<view v-for="index of 5" />`,
`<view wx:for="{{a}}" wx:for-item="index" wx:for-index="i0"/>`,
`(_ctx, _cache) => {
return { a: _f(5, (index, k0, i0) => { return {}; }) }
}`
......
......@@ -123,11 +123,15 @@ function genVFor(
node: ForElementNode,
{ push, directive }: TemplateCodegenContext
) {
const { sourceCode, valueAlias } = node.vFor
const { sourceCode, valueAlias, indexAlias } = node.vFor
push(` ${directive}for="${sourceCode}"`)
debugger
if (valueAlias) {
push(` ${directive}for-item="${valueAlias}"`)
}
if (valueAlias === 'index') {
push(` ${directive}for-index="${indexAlias}"`)
}
const keyProp = findProp(node, 'key', true)
if (keyProp) {
const key = ((keyProp as DirectiveNode).exp as SimpleExpressionNode).content
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册