From eab35ad41591d6ee979e23c3ef7bd89dadc4c2d6 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Fri, 10 Jun 2022 12:03:50 +0800 Subject: [PATCH] fix(mp): nested slots v-for (#3587) --- .../__tests__/scopedSlot.spec.ts | 18 ++++++++++++++++++ .../uni-mp-compiler/__tests__/slot.spec.ts | 2 +- .../src/transforms/transformSlot.ts | 2 +- packages/uni-mp-vue/lib/vue.runtime.esm.js | 2 +- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/packages/uni-mp-compiler/__tests__/scopedSlot.spec.ts b/packages/uni-mp-compiler/__tests__/scopedSlot.spec.ts index 09d536e9b..274def241 100644 --- a/packages/uni-mp-compiler/__tests__/scopedSlot.spec.ts +++ b/packages/uni-mp-compiler/__tests__/scopedSlot.spec.ts @@ -25,6 +25,24 @@ describe('compiler: transform scoped slots', () => { ``, `(_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( + ``, + ``, + `(_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( + ``, + ``, + `(_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 }; }) } }` ) }) diff --git a/packages/uni-mp-compiler/__tests__/slot.spec.ts b/packages/uni-mp-compiler/__tests__/slot.spec.ts index 76147a7be..98931b212 100644 --- a/packages/uni-mp-compiler/__tests__/slot.spec.ts +++ b/packages/uni-mp-compiler/__tests__/slot.spec.ts @@ -99,7 +99,7 @@ describe('compiler: transform slot', () => { ``, ``, `(_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 }; }) } }` ) }) diff --git a/packages/uni-mp-compiler/src/transforms/transformSlot.ts b/packages/uni-mp-compiler/src/transforms/transformSlot.ts index 8155aaaaf..90b8dd845 100644 --- a/packages/uni-mp-compiler/src/transforms/transformSlot.ts +++ b/packages/uni-mp-compiler/src/transforms/transformSlot.ts @@ -97,7 +97,7 @@ export function rewriteSlot(node: SlotOutletNode, context: TransformContext) { slotName, ',', `{${properties.join(',')}}`, - `${vForIndexAlias ? ',' + vForIndexAlias : ''}`, + `${vForIndexAlias ? ',' + parseScopedSlotKey(context) : ''}`, ')', ]), context diff --git a/packages/uni-mp-vue/lib/vue.runtime.esm.js b/packages/uni-mp-vue/lib/vue.runtime.esm.js index d2747291d..6113ef91c 100644 --- a/packages/uni-mp-vue/lib/vue.runtime.esm.js +++ b/packages/uni-mp-vue/lib/vue.runtime.esm.js @@ -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; -- GitLab