dcloudio / dcloudio/uni-app

组件中 slot 外层设置 v-if 在页面中使用 slot 内的组件 ref 获取实例为 null

Open
#5,513 17 comments 0 reactions 0 assignees View on GitHub
bug mp-weixin
Dominant language
JavaScript
Stars
41.6k
Forks
3.7k
Avg merge
7h 6m
Merged PRs (30d)
6

Description

### 发行方式

小程序

### 具体平台

微信小程序

### 开发环境

macOS

### 项目创建方式

CLI命令行

### 依赖版本

"@dcloudio/uni-app": "3.0.0-4040520250104002",
"@dcloudio/uni-app-harmony": "3.0.0-4040520250104002",
"@dcloudio/uni-app-plus": "3.0.0-4040520250104002",
"@dcloudio/uni-components": "3.0.0-4040520250104002",
"@dcloudio/uni-h5": "3.0.0-4040520250104002",
"@dcloudio/uni-mp-alipay": "3.0.0-4040520250104002",
"@dcloudio/uni-mp-baidu": "3.0.0-4040520250104002",
"@dcloudio/uni-mp-jd": "3.0.0-4040520250104002",
"@dcloudio/uni-mp-kuaishou": "3.0.0-4040520250104002",
"@dcloudio/uni-mp-lark": "3.0.0-4040520250104002",
"@dcloudio/uni-mp-qq": "3.0.0-4040520250104002",
"@dcloudio/uni-mp-toutiao": "3.0.0-4040520250104002",
"@dcloudio/uni-mp-weixin": "3.0.0-4040520250104002",
"@dcloudio/uni-mp-xhs": "3.0.0-4040520250104002",
"@dcloudio/uni-quickapp-webview": "3.0.0-4040520250104002",

### 问题描述

```TypeScript

import Page from '@/components/page/page.vue';
import Popup from '@/components/popup/popup.vue';

import MyTip from './components/my-tip/my-tip.vue';

const popupRef = ref<InstanceType<typeof Popup>>();
const pageRef = ref<InstanceType<typeof Page>>();

function openPopup() {
popupRef.value?.open();
}




获取用户详情1


123



```

popupRef 获取到为 undefined

### 重现步骤

isSuccess 初始化接口调用完成后才会为 true

### 期望行为

应该可以获取到实例

### 实际行为

获取到 undefined

### 截图或录屏

![Image](https://github.com/user-attachments/assets/1f9aac97-3568-4054-8c75-52be417b9b09)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.