1- import  {  hasOwn ,  isFunction ,  isString  }  from  '@vue/shared' 
1+ import  {  hasOwn ,  isArray ,   isFunction ,  isString  }  from  '@vue/shared' 
22
33import  { 
44  type  ComponentInternalInstance , 
@@ -146,7 +146,7 @@ export function handleRef(this: MPComponentInstance, ref: MPComponentInstance) {
146146    if  ( isString ( refInForName ) )  { 
147147      ; ( refs [ refInForName ]  ||  ( refs [ refInForName ]  =  [ ] ) ) . push ( refValue ) 
148148    }  else  { 
149-       setRef ( refInForName ,  refValue ,  refs ,  setupState ) 
149+       setRef ( refInForName ,  refValue ,  refs ,  setupState ,   true ) 
150150    } 
151151  } 
152152} 
@@ -170,14 +170,26 @@ function setRef(
170170  ref : Ref  |  ( ( ref : object  |  null ,  refs : Record < string ,  any > )  =>  void ) , 
171171  refValue : ComponentPublicInstance , 
172172  refs : Record < string ,  unknown > , 
173-   setupState : Data 
173+   setupState : Data , 
174+   isRefInVFor  =  false 
174175)  { 
175176  if  ( isRef ( ref ) )  { 
176177    ref . value  =  refValue 
177178  }  else  if  ( isFunction ( ref ) )  { 
178179    const  templateRef  =  ref ( refValue ,  refs ) 
179180    if  ( isTemplateRef ( templateRef ) )  { 
180181      setTemplateRef ( templateRef ,  refValue ,  setupState ) 
182+       // 对于 template ref,需要手动同步到 refs,否则 getCurrentInstance().proxy.$refs 获取不到 
183+       if  ( ! templateRef . k  ||  ! isRef ( templateRef . r ) )  { 
184+         return 
185+       } 
186+       if  ( isRefInVFor )  { 
187+         ; ( 
188+           ( refs [ templateRef . k ]  ||  ( refs [ templateRef . k ]  =  [ ] ) )  as  unknown [ ] 
189+         ) . push ( refValue ) 
190+       }  else  { 
191+         refs [ templateRef . k ]  =  refValue 
192+       } 
181193    } 
182194  } 
183195} 
0 commit comments