uni-app icon indicating copy to clipboard operation
uni-app copied to clipboard

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

Open zxj176381 opened this issue 5 months ago • 16 comments
trafficstars

发行方式

小程序

具体平台

微信小程序

开发环境

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",

问题描述

<script lang="ts" setup>
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();
}
</script>

<template>
  <Page ref="pageRef">
    <template #page="{ isSuccess }">
      <div v-if="isSuccess">
        <view @click="openPopup">获取用户详情1</view>
        <MyTip />
        <Popup ref="popupRef">
          <view class="h-[400px] bg-white">123</view>
        </Popup>
      </div>
    </template>
  </Page>
</template>

popupRef 获取到为 undefined

重现步骤

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

期望行为

应该可以获取到实例

实际行为

获取到 undefined

截图或录屏

Image

zxj176381 avatar Jun 06 '25 07:06 zxj176381