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

fix(mp): nested slots v-for (#3587)

上级 572ee5cb
......@@ -25,6 +25,24 @@ describe('compiler: transform scoped slots', () => {
`<view><slot wx:if="{{a}}" name="header"/></view>`,
`(_ctx, _cache) => {
return _e({ a: _ctx.ok }, _ctx.ok ? { b: _r("header", { item: _ctx.item, index: _ctx.index }) } : {})
}`
)
})
test('v-for + v-for + scoped slots', () => {
assert(
`<view v-for="(item, index) in 4" :key="index"><view v-for="(item, index) in 4"><slot :text="1"></slot></view></view>`,
`<view wx:for="{{a}}" wx:for-item="item" wx:key="b"><view wx:for="{{item.a}}" wx:for-item="item"><slot name="{{item.a}}"></slot></view></view>`,
`(_ctx, _cache) => {
return { a: _f(4, (item, index, i0) => { return { a: _f(4, (item, index, i1) => { return { a: "d-" + i0 + '-' + i1, b: _r("d", { text: 1 }, i0 + '-' + i1) }; }), b: index }; }) }
}`
)
})
test('v-for + v-for + v-for + scoped slots', () => {
assert(
`<view v-for="(item, index) in 4" :key="index"><view v-for="(item, index) in 4"><view v-for="(item, index) in 4"><slot :text="1"></slot></view></view></view>`,
`<view wx:for="{{a}}" wx:for-item="item" wx:key="b"><view wx:for="{{item.a}}" wx:for-item="item"><view wx:for="{{item.a}}" wx:for-item="item"><slot name="{{item.a}}"></slot></view></view></view>`,
`(_ctx, _cache) => {
return { a: _f(4, (item, index, i0) => { return { a: _f(4, (item, index, i1) => { return { a: _f(4, (item, index, i2) => { return { a: "d-" + i0 + '-' + i1 + '-' + i2, b: _r("d", { text: 1 }, i0 + '-' + i1 + '-' + i2) }; }) }; }), b: index }; }) }
}`
)
})
......
......@@ -99,7 +99,7 @@ describe('compiler: transform slot', () => {
`<view v-for="(item,index) in items" :key="index"><slot v-for="(item1,index1) in item.list" :key="index1"></slot></view>`,
`<view wx:for="{{a}}" wx:for-item="item" wx:key="b"><slot wx:for="{{item.a}}" wx:for-item="item1" name="{{item1.a}}"></slot></view>`,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, index, i0) => { return { a: _f(item.list, (item1, index1, i1) => { return { a: "d-" + i0 + '-' + i1, b: _r("d", { key: index1 }, i1) }; }), b: index }; }) }
return { a: _f(_ctx.items, (item, index, i0) => { return { a: _f(item.list, (item1, index1, i1) => { return { a: "d-" + i0 + '-' + i1, b: _r("d", { key: index1 }, i0 + '-' + i1) }; }), b: index }; }) }
}`
)
})
......
......@@ -97,7 +97,7 @@ export function rewriteSlot(node: SlotOutletNode, context: TransformContext) {
slotName,
',',
`{${properties.join(',')}}`,
`${vForIndexAlias ? ',' + vForIndexAlias : ''}`,
`${vForIndexAlias ? ',' + parseScopedSlotKey(context) : ''}`,
')',
]),
context
......
......@@ -4989,7 +4989,7 @@ function componentUpdateScopedSlotsFn() {
const diffData = Object.create(null);
scopedSlotsData.forEach(({ path, index, data }) => {
const oldScopedSlotData = getValueByDataPath(oldData, path);
const diffPath = `${path}[${index}]`;
const diffPath = isString(index) ? `${path}.${index}` : `${path}[${index}]`;
if (typeof oldScopedSlotData === 'undefined' ||
typeof oldScopedSlotData[index] === 'undefined') {
diffData[diffPath] = data;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册