this.$refs获取不到子组件
时间: 2023-09-09 12:13:52 浏览: 189
问题的原因是在调用this.$refs获取子组件时,可能子组件还未渲染完成。为了解决这个问题,可以在mounted生命周期钩子中使用this.$nextTick来确保子组件已经渲染完成。\[1\]另外,如果ref是循环出来的,有多个重名,那么ref的值会是一个数组,此时可以通过循环来获取单个的ref。\[2\]如果是父组件调用子组件方法时出现这种情况,也可以在调用方法的时候使用this.$nextTick来确保子组件已经渲染成功。\[3\]
#### 引用[.reference_title]
- *1* [this.$refs获取不到子组件](https://blog.csdn.net/weixin_43239880/article/details/124165856)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [this.$refs 获取不到解决办法](https://blog.csdn.net/poppymilan/article/details/108448352)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [vue 父组件使用this.$refs调用子组件报错,undefined、not a function问题解决方法](https://blog.csdn.net/m0_58893670/article/details/130379816)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文