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>
相关推荐
是烟花哈4 小时前
【前端】React框架学习
前端·学习·react.js
qq4356947014 小时前
JavaWeb08
前端
2401_878454535 小时前
html和css的复习(1)
前端·css·html
@PHARAOH5 小时前
WHAT - git worktree 概念
前端·git
IT_陈寒6 小时前
我竟然被JavaScript的隐式类型转换坑了三天!
前端·人工智能·后端
我亚索贼六丶6 小时前
二十六. AI基础概念之如何更好的使用AI
前端
小码哥_常6 小时前
安卓启动页Logo适配秘籍:告别“奇形怪状”的展示
前端
我亚索贼六丶6 小时前
二十五.Electron 初体验与进阶
前端
当时只道寻常6 小时前
像使用 Redis 一样操作 LocalStorage
前端·前端工程化
RONIN6 小时前
UI组件库elementplus
前端