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>
相关推荐
勇往直前plus31 分钟前
Vue3(篇一) 核心概念——响应式模板语法与组件基础
前端·javascript·vue.js
咩咩啃树皮40 分钟前
第43篇:Vue3计算属性(computed)完全精讲——缓存机制、依赖计算、业务最优解
前端·vue.js·缓存
用户938515635072 小时前
从零搭建 AI 日记助手:用 Milvus 向量数据库 + RAG 让机器读懂你的每一天
javascript·人工智能·全栈
徐小夕3 小时前
花了一周,3亿tokens,我开源了一款 Word 文档智能审查平台,文稿自动质检+可视化分析,告别低效人工审核
前端·算法·github
a1117763 小时前
坦克大战3D Three.js 3D (开源项目)
开发语言·javascript·3d
kyriewen4 小时前
别再乱用useEffect了——你写的10个里有8个不该存在
前端·javascript·react.js
Ivanqhz4 小时前
Rust &‘static str浅析
java·前端·javascript·rust
IT_陈寒5 小时前
SpringBoot这个分页坑,我踩了三天才爬出来
前端·人工智能·后端
颜酱5 小时前
05 | 召回前置准备:根据业务数据库生成各数据库(读取配置阶段)
前端·人工智能·后端
zandy10115 小时前
衡石 Agentic BI的ReAct 推理框架在 Agentic BI 中的工程化实践
前端·javascript·react.js