不使用 el-popover 组件手动创建一个 div 作为 Popover

  1. 不使用 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>
  2. 使用 CSS 控制 Popover 的样式

    复制代码
    .popover {
      position: absolute;
      z-index: 100;
      background-color: #fff;
      border: 1px solid #ccc;
      padding: 10px;
      display: none; /* 默认不显示 */
    }
  3. 在 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;
        }
      }
    };
相关推荐
anOnion31 分钟前
构建无障碍组件之Menu Button pattern
前端·html·交互设计
米丘14 小时前
微前端之 Web Components 完全指南
微服务·html
秃头网友小李3 天前
前端难点:keep-alive 缓存什么?RouterView 的 key 为什么要带 scopeId?
前端·vue.js
徐小夕3 天前
JitWord 3.0 正式发布,高精度Word异构解析+复杂组件兼容,打造web端协同Word编辑器
前端·vue.js·算法
奋斗吧程序媛3 天前
补充一个小知识点:有关@click.native
前端·vue.js
英勇无比的消炎药3 天前
一行命令背后:TinyRobot CLI 如何重构 AI 对话接入的效率范式
vue.js·aigc
Metaphor6923 天前
使用 Python 将 PDF 转换为 HTML
python·pdf·html
jay神3 天前
基于 FastAPI + Vue 的宠物领养管理系统
前端·vue.js·python·毕业设计·fastapi·宠物
一杯奶茶¥3 天前
水果销售网站 CRM客户信息管理系统 超市管理系 酒店管理系统 健身房管理系统 在线音乐网站 校园招聘系统
java·vue.js·spring boot·mysql·spring·java项目
英勇无比的消炎药3 天前
一站式搞定品牌风格:TinyRobot 主题定制从入门到精通
vue.js