uni-app uni-data-select 在uni-popup中选择下拉列表时无法显示出来

发布于 1周前 作者 ionicwang 来自 Uni-App

uni-app uni-data-select 在uni-popup中选择下拉列表时无法显示出来

示例代码:

<template>  
<view>  
<button class="more-popup-botton" type="primary" @click="onOpenSetHeadModal">打开popup</button>  
    <uni-popup ref="headPopupRef" type="bottom" class="head-popup" background-color="#fff">  
        <view class="" style="margin: 10px 10px;">  
            <uni-forms :modelValue="sapHeadInfo" label-width="100">  
                <uni-forms-item label="日期1">  
                    <uni-datetime-picker type="datetime" v-model="sapHeadInfo.datetimesingle" />  
                </uni-forms-item>  
                <uni-forms-item label="日期2">  
                    <uni-datetime-picker type="datetime" v-model="sapHeadInfo.datetimesingle" />  
                </uni-forms-item>  
                <uni-forms-item label="文本">  
                    <uni-data-select v-model="sapHeadInfo.headText" :localdata="status"></uni-data-select>  
                </uni-forms-item>  
            </uni-forms>  
        </view>  
    </uni-popup>  
</view>  
</template>  
<script setup>  
import {ref} from 'vue'  
const headPopupRef  = ref(null);  
function onOpenSetHeadModal(){  
headPopupRef.value.open();  
}  
const status = ['苹果','香蕉','糙米']  
</script>

操作步骤:



## 预期结果:

下拉框能够自动向上面显示



## 实际结果:

不显示



## bug描述:

uni-data-select 在uni-popup中选择下拉列表时,无法显示出来


![示例图片](https://www.itying.com/uniimg.php?url=https://img-cdn-tc.dcloud.net.cn/uploads/questions/20231117/c635e4675d5eeaad9dd69d547385b1ef.jpg)

| 信息类别 | 详情 |
| --- | --- |
| 产品分类 | uniapp/H5 |
| PC开发环境操作系统 | Windows |
| PC开发环境操作系统版本号 | 11 |
| HBuilderX类型 | 正式 |
| HBuilderX版本号 | 3.97 |
| 浏览器平台 | Chrome |
| 浏览器版本 | 119.0.6045.159 |
| 项目创建方式 | HBuilderX |

3 回复

这个不是没显示出来 而是被盖住了 uni-data-select的下拉元素本身就是通过定位来实现的 而且你这选择框还处于页面最底部 刚好被遮盖住了 给popup的字元素增加高度就能看到下面的选择项了 <uni-popup ref="headPopupRef" type="bottom" class="head-popup" background-color="#fff">
<view class="" style="margin: 10px 10px;overflow-y: scroll;height: 40vh;">
<uni-forms :modelValue="sapHeadInfo" label-width="100">
<uni-forms-item label="日期1">
<uni-datetime-picker type="datetime" v-model="sapHeadInfo.datetimesingle" />
</uni-forms-item>
<uni-forms-item label="日期2">
<uni-datetime-picker type="datetime" v-model="sapHeadInfo.datetimesingle" />
</uni-forms-item>
<uni-forms-item label="文本">
<uni-data-select v-model="sapHeadInfo.headText" :localdata="status"></uni-data-select>
</uni-forms-item>
</uni-forms>
</view>
</uni-popup>
不过建议你使用picker组件来实现这个表单项的选择功能


改一下,可以的
const status = reactive([{
text: “苹果”,
value: “10001”,
}, {
text: “香蕉”,
value: “10002”,
}, {
text: “糙米”,
value: “10004”,
}])

uni-app 中使用 uni-data-select 组件时,如果将其放置在 uni-popup 中,可能会出现下拉列表无法显示的问题。这通常是由于 uni-popup 的层级和样式设置导致的。以下是一些可能的解决方案:

1. 调整 z-index

uni-popup 的默认 z-index 可能较低,导致下拉列表被遮挡。你可以尝试调整 uni-popupuni-data-selectz-index 值,确保下拉列表能够显示在最上层。

<uni-popup ref="popup" :z-index="9999">
  <uni-data-select :z-index="10000"></uni-data-select>
</uni-popup>

2. 使用 uni-popup-dialog

uni-popup-dialoguni-popup 的一种类型,它通常用于显示对话框内容。你可以尝试将 uni-data-select 放在 uni-popup-dialog 中,看看是否能解决问题。

<uni-popup ref="popup" type="dialog">
  <uni-data-select></uni-data-select>
</uni-popup>

3. 手动控制 uni-popup 的显示和隐藏

在某些情况下,uni-popup 的自动关闭机制可能会影响 uni-data-select 的下拉列表显示。你可以尝试手动控制 uni-popup 的显示和隐藏,确保在下拉列表显示时 uni-popup 不会自动关闭。

<template>
  <view>
    <button @click="showPopup">显示弹出层</button>
    <uni-popup ref="popup" :mask-click="false">
      <uni-data-select @change="onSelectChange"></uni-data-select>
    </uni-popup>
  </view>
</template>

<script>
export default {
  methods: {
    showPopup() {
      this.$refs.popup.open();
    },
    onSelectChange() {
      this.$refs.popup.close();
    }
  }
}
</script>

4. 使用 uni-popupcustom 模式

uni-popupcustom 模式允许你完全自定义弹出层的内容和样式。你可以尝试使用 custom 模式来避免默认样式带来的问题。

<template>
  <view>
    <button @click="showPopup">显示弹出层</button>
    <uni-popup ref="popup" type="custom">
      <view class="custom-popup">
        <uni-data-select></uni-data-select>
      </view>
    </uni-popup>
  </view>
</template>

<script>
export default {
  methods: {
    showPopup() {
      this.$refs.popup.open();
    }
  }
}
</script>

<style>
.custom-popup {
  background-color: #fff;
  padding: 20px;
  border-radius: 10px;
}
</style>

5. 检查 uni-data-select 的版本和兼容性

确保你使用的 uni-data-selectuni-popup 版本是最新的,并且它们之间没有兼容性问题。如果有必要,可以尝试更新或降级相关组件。

6. 使用其他下拉选择组件

如果以上方法都无法解决问题,你可以考虑使用其他下拉选择组件,例如 uni-comboxuni-picker,它们可能更适合在 uni-popup 中使用。

<uni-popup ref="popup">
  <uni-combox :options="options"></uni-combox>
</uni-popup>
回到顶部
AI 助手
你好,我是IT营的 AI 助手
您可以尝试点击下方的快捷入口开启体验!