不使用 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;
        }
      }
    };
相关推荐
oden6 小时前
2025博客框架选择指南:Hugo、Astro、Hexo该选哪个?
前端·html
汝生淮南吾在北8 小时前
SpringBoot+Vue超市收银管理系统
vue.js·spring boot·后端
p***93038 小时前
SpringBoot + vue 管理系统
vue.js·spring boot·后端
8***v2579 小时前
SpringBoot + vue 管理系统
vue.js·spring boot·后端
tsumikistep9 小时前
【前后端】Vue 脚手架与前端工程结构入门指南
前端·javascript·vue.js
华仔啊10 小时前
Vue3 + Element Plus 动态菜单实现:一套代码完美适配多角色权限系统
前端·vue.js
姜太公钓鲸23310 小时前
Bootstrap是什么?作用是什么?使用场景是什么?如何使用?
前端·bootstrap·html
慧慧吖@10 小时前
关于在本地去模拟生产环境检测页面内容注意事项
前端·javascript·vue.js
黄团团11 小时前
Vue2整合Electron开发桌面级应用以及打包发布(提供Gitee源码)
前端·javascript·vue.js·elementui·electron
Aerelin11 小时前
iframe讲解(爬虫playwright的特殊应用)
前端·爬虫·python·html