From 05ce50ee73d26c3304d002cb338d16d6f548a3f4 Mon Sep 17 00:00:00 2001 From: chouchouji <1305974212@qq.com> Date: Thu, 28 Aug 2025 16:19:16 +0800 Subject: [PATCH] =?UTF-8?q?fix(mp-alipay):=20=E4=BF=AE=E5=A4=8D=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E9=80=9A=E8=BF=87=20instance.proxy.$refs=20=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E7=BB=84=E4=BB=B6=E5=AE=9E=E4=BE=8B=E7=9A=84=20Bug=20?= =?UTF-8?q?(question/213028)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/uni-mp-alipay/src/runtime/util.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/uni-mp-alipay/src/runtime/util.ts b/packages/uni-mp-alipay/src/runtime/util.ts index f57a1d9b150..47a85a51ded 100644 --- a/packages/uni-mp-alipay/src/runtime/util.ts +++ b/packages/uni-mp-alipay/src/runtime/util.ts @@ -146,7 +146,7 @@ export function handleRef(this: MPComponentInstance, ref: MPComponentInstance) { if (isString(refInForName)) { ;(refs[refInForName] || (refs[refInForName] = [])).push(refValue) } else { - setRef(refInForName, refValue, refs, setupState) + setRef(refInForName, refValue, refs, setupState, true) } } } @@ -170,7 +170,8 @@ function setRef( ref: Ref | ((ref: object | null, refs: Record) => void), refValue: ComponentPublicInstance, refs: Record, - setupState: Data + setupState: Data, + isRefInVFor = false ) { if (isRef(ref)) { ref.value = refValue @@ -178,6 +179,17 @@ function setRef( const templateRef = ref(refValue, refs) if (isTemplateRef(templateRef)) { setTemplateRef(templateRef, refValue, setupState) + // 对于 template ref,需要手动同步到 refs,否则 getCurrentInstance().proxy.$refs 获取不到 + if (!templateRef.k || !isRef(templateRef.r)) { + return + } + if (isRefInVFor) { + ;( + (refs[templateRef.k] || (refs[templateRef.k] = [])) as unknown[] + ).push(refValue) + } else { + refs[templateRef.k] = refValue + } } } }