提交 f022135d 编写于 作者: Q qiang

fix: slot with v-for question/130258

上级 27cebeb2
......@@ -193,6 +193,17 @@ describe('codegen', () => {
`with(this){return _c('p',{slot:"one"})}`
)
})
it('generate slot with v-for', () => {
assertCodegen(
'<div><slot v-for="item in list"></slot></div>',
`with(this){return _c('div',[_l((_$s(1,'f',{forItems:list})),function(item,$10,$20,$30){return _t("default",null,{"_i":("1-"+$30),"key":_$s(1,'f',{forIndex:$20,key:1+'-'+$30})})})],2)}`
)
assertCodegen(
'<div><template v-for="item in list"><slot></slot></template></div>',
`with(this){return _c('div',[_l((_$s(1,'f',{forItems:list})),function(item,$10,$20,$30){return [_t("default",null,{"_i":("2-"+$30),"key":_$s(1,'f',{forIndex:$20,keyIndex:0,key:1+'-0'+$30})})]})],2)}`
)
})
it('generate scoped slot', () => {
assertCodegen(
......
......@@ -72,6 +72,9 @@ function parseKey (el, isScopedSlot) {
const keyIndex = forEl.children.indexOf(el)
el.key = genVar(V_FOR, `{forIndex:${it},keyIndex:${keyIndex},key:${el.key}}`)
}
if (el.tag === 'slot') {
el.attrs.push({ name: 'key', value: el.key })
}
}
function parseComponentAttrs (el, genVar) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册