基于element UI el-dropdown打造表格操作列的“更多⌵”上下文关联菜单

html 复制代码
<template>
  <div :class="$options.name">
    <el-table :data="tableData">
      <el-table-column type="index" label="序号" width="60" />

      <!-- 主要列 BEGIN---------------------------------------- -->

      <el-table-column label="姓名">
        <template slot-scope="scope">
          <span>{{ scope.row.name }}</span>
        </template>
      </el-table-column>

      <!-- 主要列 END---------------------------------------- -->

      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            @click.stop="edit(scope.row)"
            @dblclick.native.stop
            >修改</el-button
          >
          <el-button
            size="mini"
            type="danger"
            @click.stop="del(scope.row)"
            @dblclick.native.stop
            >删除</el-button
          >
          <!-- 更多操作 -->
          <el-dropdown
            style="margin-left: 10px"
            :show-timeout="0"
            :placement="`bottom-end`"
            @command="(c) => dropdownItems.find((v) => v.label == c).clickEvent(c, scope)"
          >
            <span style="cursor: default">更多<i class="el-icon-arrow-down" /></span>
            <el-dropdown-menu
              slot="dropdown"
              style="
                transition: none;
                overflow-y: auto;
                max-height: 400px;
                margin-top: 5px;
              "
            >
              <el-dropdown-item
                v-for="(d, i) in dropdownItems"
                :command="d.label"
                :key="i"
                :divided="d.divided"
                v-if="typeof d.hide === 'function' ? !d.hide(d, scope) : !d.hide"
                :disabled="
                  typeof d.disabled === 'function' ? d.disabled(d, scope) : d.disabled
                "
                :type="d.type"
              >
                <i :class="d.icon" v-if="d.icon" />{{ d.label }}
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
export default {
  name: "moreDropdown",
  data() {
    return {
      dropdownItems: [
        {
          hide: true,
          label: "编辑",
          clickEvent: (c, scope) => {
            // this.edit(scope.row);
          },
        },
        {
          disabled: true,
          label: "重命名",
          icon: `el-icon-edit`,
          clickEvent: (c, scope) => {
            // this.edit_rename(scope.row);
          },
        },
        {
          label: "分享",
          icon: `el-icon-share`,
          clickEvent: (c, scope) => {
            console.log(c, scope.row);
            // this.share(scope.row);
          },
        },
        {
          label: "下载",
          type: "success",
          icon: `el-icon-download`,
          clickEvent: (c, scope) => {
            console.log(c, scope.row);
            // this.download(scope.row);
          },
        },
        {
          divided: true,
          label: "删除",
          icon: `el-icon-delete`,
          type: "danger",
          clickEvent: (c, scope) => {
            // this.del([scope.row]);
          },
        },
      ],

      tableData: [
        { name: "姓名1" },
        { name: "姓名2" },
        { name: "姓名3" },
        { name: "姓名4" },
        { name: "姓名5" },
      ],
    };
  },
};
</script>
<style lang="scss" scoped>
.moreDropDown {
  // 下拉选择菜单----------------------------------------
  .el-dropdown-menu__item {
    &[type="danger"] {
      color: #f56c6c;

      &:hover {
        color: #f56c6c;
        background-color: #f56c6c22;
      }
    }

    &[type="success"] {
      color: #67c23a;

      &:hover {
        color: #67c23a;
        background-color: #67c23a22;
      }
    }

    &[type="warning"] {
      color: #e6a23c;

      &:hover {
        color: #e6a23c;
        background-color: #e6a23c22;
      }
    }

    &[type="info"] {
      color: #909399;

      &:hover {
        color: #909399;
        background-color: #90939922;
      }
    }
  }
}
</style>

【sgs】自定义组件:简洁版搜索栏筛选框组件(点击筛选条件按钮才出现复杂的、可自定义的筛选组合条件;当页面宽度不足以显示所有操作按钮的时候,自动折叠为"更多操作⌵"上下文关联按钮)。_sorttype' => 'all-CSDN博客文章浏览阅读103次。【代码】【sgs】自定义组件:简洁版搜索栏筛选框组件(点击筛选条件按钮才出现复杂的、可自定义的筛选组合条件;当页面宽度不足以显示所有操作按钮的时候,自动折叠为"更多操作..."上下文关联按钮)。_sorttype' => 'allhttps://blog.csdn.net/qq_37860634/article/details/144657057

相关推荐
JieE2128 小时前
LeetCode 101. 对称二叉树|JS 递归 + 迭代双解法,彻底搞懂镜像判断
javascript·算法
冬奇Lab10 小时前
AI Workflow 定义的四次演进:从 Markdown 到 JS 脚本,再到分布式多 Agent
javascript·人工智能·agent
一颗烂土豆16 小时前
Meshopt 压缩深度解析,为什么它比 Draco 更快
前端·javascript·webgl
kyriewen19 小时前
同事每天催我 Code Review,我写了个脚本让 AI 替我 review PR——现在他反过来催 AI 了
前端·javascript·ai编程
weedsfly21 小时前
迭代器、生成器与异步迭代——让数据“按需流动”的艺术
前端·javascript
假如让我当三天老蒯21 小时前
前端跨域解决方案(学习用)
前端·javascript·面试
铁皮饭盒1 天前
Bun 哪比 Node.js 快?
javascript·后端
JieE2121 天前
LeetCode 56. 合并区间|超清晰 JS 图解思路,面试高频区间题
javascript·算法·面试
candyTong1 天前
RTK 技术原理:一次典型会话里,80% 上下文是怎么省下来的
javascript·后端·架构
_柳青杨2 天前
深入理解 JavaScript 事件循环
前端·javascript