-
不使用
el-popover组件,而是手动创建一个div作为 Popover:<template> <el-table :data="tableData"> <!-- ...其他列 --> <el-table-column label="操作"> <template slot-scope="scope"> <div class="popover-trigger" @click="showPopover(scope.$index)"> 显示 Popover </div> <div class="popover" v-show="scope.row.showPopover" ref="popover"> 这里是一些内容 <el-button size="mini" @click="hidePopover(scope.$index)">关闭</el-button> </div> </template> </el-table-column> </el-table> </template> -
使用 CSS 控制 Popover 的样式:
.popover { position: absolute; z-index: 100; background-color: #fff; border: 1px solid #ccc; padding: 10px; display: none; /* 默认不显示 */ } -
在 Vue 方法中控制显示和隐藏:
export default { data() { return { tableData: [ // ...表格数据 { showPopover: false }, // ...其他行数据 ], }; }, methods: { showPopover(index) { const popover = this.$refs.popover[index]; const trigger = this.$el.querySelector(`.popover-trigger`); // 假设每个触发器都有这个类名 if (trigger) { popover.style.left = `${trigger.offsetLeft}px`; popover.style.top = `${trigger.offsetTop + trigger.offsetHeight}px`; popover.style.display = 'block'; } this.tableData[index].showPopover = true; }, hidePopover(index) { this.tableData[index].showPopover = false; } } };
不使用 el-popover 组件手动创建一个 div 作为 Popover
Light_102025-01-03 8:23
相关推荐
软件技术NINI1 小时前
盗墓笔记html+css+js 2页ShuiShenHuoLe2 小时前
Go html/template 使用入门午安~婉2 小时前
挑战二:博客预览卡片林焱_RPAAI17 小时前
影刀RPA技术深度:CSS选择器高级实战指南——伪类属性选择器与性能对比完全解析陳陈陳18 小时前
🚀 前端流式输出革命:SSE + BFF 架构从零到一实战指南黄泉路醉s1 天前
在Vant+Vue+TypeScript的H移动前端使用UnoCSSIMPYLH1 天前
HTML 的 <dt> 元素我要两颗404西柚1 天前
Stage three:VUE工程化与实战工具IMPYLH1 天前
HTML 的 <em> 元素看昭奚恤哭1 天前
基于 RuoYi-Vue-Pro 定制了一个后台管理系统 magic-admin , 开源出来!