Element Plus的MessageBox组件被table表格组件遮挡

Element Plus的MessageBox组件被table表格组件遮挡,问题如图:

通过审查元素发现z-index是足够高的。

通过右侧的样式警告信息,发现是因为没有设置position导致z-index不生效(position默认为static)


那么解决办法就很简单了 直接给messagebox加上position: relative; 就不会遮挡了。

.is-message-box {
  position: relative;
}

结果:

### 实现 Element Plus MessageBox 中嵌套 El-Select 组件 为了实现在 `MessageBox` 对话框中嵌入 `El-Select` 下拉选择器的功能,可以按照如下方式构建代码结构。此方法允许在对话框内部动态加载并展示选项列表。 #### 创建自定义表单组件用于 MessageBox 内部调用 首先创建一个独立的 Vue 组件作为表单的一部分,在其中引入所需的 `El-Select` 和其他必要的输入控件: ```html <template> <div class="custom-form"> <!-- 使用 el-select 进行数据绑定 --> <el-select v-model="selectedValue" placeholder="请选择..."> <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"> </el-option> </el-select> <!-- 可选:添加更多字段或按钮 --> </div> </template> <script setup lang="ts"> import { ref, reactive } from 'vue'; // 定义可选项数组 const options = [ { value: 'option1', label: '黄金糕' }, /* 更多配置 */ ]; let selectedValue = ref(''); </script> ``` #### 调用 MessageBox 并传入上述定制化的表单模板 通过 `ElMessagebox` API 方法来打开带有自定义内容的消息框,并传递之前准备好的组件实例给它。注意这里要确保正确处理关闭事件以及获取最终的选择结果。 ```javascript import { defineComponent } from 'vue'; import { ElButton, ElMessageBox } from 'element-plus'; import CustomForm from './CustomForm.vue'; // 假设上面的 HTML 部分保存为单独文件 export default defineComponent({ name: 'App', components: { ElButton, }, methods: { openDialog() { const formInstance = new (Vue.extend(CustomForm))(); ElMessageBox.alert(formInstance.$mount().$el, '', { title: '提示', dangerouslyUseHTMLString: true, showConfirmButton: false, beforeClose(action, instance, done) { setTimeout(() => { console.log('Selected Value:', formInstance.selectedValue); done(); }, 1000); // 模拟异步操作延迟执行完成回调 } }); } } }); ``` 以上实现了在一个消息框里边放置了一个可以选择项目的下拉菜单[^1]。需要注意的是实际项目开发过程中可能还需要考虑样式调整等问题以适应不同场景下的需求[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值