TABLE使用篇之奇门异术

table使用时候有时候会有下面界面

hover提示框,用element的el-popover可以显示该操作,但是会发现 取消操作的时候,el-popover不会自动消失,虽然失去焦点改框会自动消失,但是看起来对用户不是很友好

解决办法:

el-popover加个:value="visible[scope.$index]"来控制他的显示和隐藏

javascript 复制代码
<template>
  <el-table :data="tableData" style="width: 100%">
    <el-table-column prop="date" label="日期" width="180"> </el-table-column>
    <el-table-column prop="name" label="姓名" width="180"> </el-table-column>
    <el-table-column prop="address" label="地址"> </el-table-column>
    <el-table-column label="操作" min-width="90" align="center">
      <template slot-scope="scope">
        <el-popover :key="`${scope.$index}${new Date().valueOf()}del`" width="160" :value="visible[scope.$index]">
          <p>确认删除此用户吗?</p>
          <div style="text-align: right; margin: 0">
            <el-button size="mini" type="text" @click="closePopover(scope.$index)">取消</el-button>
            <el-button type="primary" size="mini" @click="deleteUser(scope.row, scope.$index)">确定</el-button>
          </div>
          <a :class="$style.edit" slot="reference">删除</a>
        </el-popover>
        <a :class="$style.dottedline">|</a>
        <el-popover
          :key="`${scope.$index}${new Date().valueOf()}reset`"
          width="160"
          :value="resetVisible[scope.$index]"
        >
          <p>确认重置此用户吗?</p>
          <div style="text-align: right; margin: 0">
            <el-button size="mini" type="text" @click="closeResetPopover(scope.$index)">取消</el-button>
            <el-button type="primary" size="mini" @click="resetPassword(scope.row, scope.$index)">确定</el-button>
          </div>
          <a :class="$style.edit" slot="reference">重置密码</a>
        </el-popover>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
export default {
  data() {
    return {
      visible: [],
      resetVisible: [],
      tableData: [
        {
          date: '2016-05-02',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1518 弄'
        },
        {
          date: '2016-05-04',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1517 弄'
        },
        {
          date: '2016-05-01',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1519 弄'
        },
        {
          date: '2016-05-03',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1516 弄'
        }
      ]
    };
  },
  methods: {
    closePopover() {
      this.visible = [];
    },
    deleteUser(index) {
      this.$set(this.visible, index, false);
    },
    closeResetPopover() {
      this.resetVisible = [];
    },
    resetPassword(index) {
      this.$set(this.resetVisible, index, false);
    }
  }
};
</script>
相关推荐
Highcharts.js1 小时前
适合报表系统的可视化图表|Highcharts支持直接导出PNG和PDF
javascript·数据库·react.js·pdf
ZC跨境爬虫1 小时前
使用Claude Code开发校园交友平台前端UI全记录(含架构、坑点、登录逻辑及算法)
前端·ui·架构
慧一居士1 小时前
Vue项目中,何时使用布局、子组件嵌套、插槽 对应的使用场景,和完整的使用示例
前端·vue.js
叫我一声阿雷吧1 小时前
JS 入门通关手册(35):执行上下文、调用栈与作用域链深度解析
javascript·作用域链·js进阶·执行上下文·调用栈·变量提升·闭包原理
Можно1 小时前
uni.request 和 axios 的区别?前端请求库全面对比
前端·uni-app
M ? A2 小时前
解决 VuReact 中 ESLint 规则冲突的完整指南
前端·react.js·前端框架
Jave21082 小时前
实现全局自定义loading指令
前端·vue.js
奔跑的呱呱牛2 小时前
CSS Grid 布局参数详解(超细化版)+ 中文注释 Demo
前端·css·grid
木斯佳3 小时前
前端八股文面经大全:影刀AI前端一面(2026-04-01)·面经深度解析
前端·人工智能·沙箱·tool·ai面经
Amumu121383 小时前
Js:正则表达式(一)
开发语言·javascript·正则表达式