TABLE使用篇之奇门异术

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

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

解决办法:

el-popover加个:value="visiblescope.$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>
相关推荐
KaMeidebaby9 小时前
卡梅德生物技术快报|PD1 单克隆抗体定制配套 N 糖全谱质控开发
前端·人工智能·算法·数据挖掘·数据分析
nuIl10 小时前
实现一个 Coding Agent(3):工具调用
前端·agent·cursor
nuIl10 小时前
实现一个 Coding Agent(4):ReAct 循环
前端·agent·cursor
nuIl10 小时前
实现一个 Coding Agent(1):一次 LLM 调用
前端·agent·cursor
nuIl10 小时前
实现一个 Coding Agent(2):让 LLM 流式响应
前端·agent·cursor
copyer_xyf10 小时前
Python 异常处理
前端·后端·python
sugar__salt10 小时前
从栈队列数据结构到JS原型面向对象全解
前端·javascript·数据结构
MageGojo10 小时前
随机文案模块怎么做?从接口封装到前端展示的完整实现思路
javascript·前端开发·api接口·后端开发·随机文案
独特的螺狮粉10 小时前
篮球集训班器具管理系统 - 鸿蒙PC Electron框架完整技术实现指南
前端·javascript·华为·electron·前端框架·开源·鸿蒙
小妖66610 小时前
js 生成随机数技巧 Math.random().toString(36)
javascript·随机数