-
不使用
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
相关推荐
anOnion31 分钟前
构建无障碍组件之Menu Button pattern米丘14 小时前
微前端之 Web Components 完全指南秃头网友小李3 天前
前端难点:keep-alive 缓存什么?RouterView 的 key 为什么要带 scopeId?徐小夕3 天前
JitWord 3.0 正式发布,高精度Word异构解析+复杂组件兼容,打造web端协同Word编辑器奋斗吧程序媛3 天前
补充一个小知识点:有关@click.native英勇无比的消炎药3 天前
一行命令背后:TinyRobot CLI 如何重构 AI 对话接入的效率范式Metaphor6923 天前
使用 Python 将 PDF 转换为 HTMLjay神3 天前
基于 FastAPI + Vue 的宠物领养管理系统一杯奶茶¥3 天前
水果销售网站 CRM客户信息管理系统 超市管理系 酒店管理系统 健身房管理系统 在线音乐网站 校园招聘系统英勇无比的消炎药3 天前
一站式搞定品牌风格:TinyRobot 主题定制从入门到精通