avue-crud中将操作栏里自己自定义的按钮合并在一起

文章讲述了如何在AvueCrud中使用ElementUI的Dropdown下拉菜单来合并按钮,以便于管理,同时实现点击分配管理员等不同功能,并处理多参数传递的问题。
摘要由CSDN通过智能技术生成

avue-crud的操作栏中自带添加,查看,编辑等按钮,我们在开发过程中往往需要自定义按钮,那按钮一多就会影响感官,所以往往会将多余的按钮合并在一个更多按钮,这里我使用的是elementui Dropdown 下拉菜单

  <avue-crud ref="crud" v-model="form" :page.sync="page" :data="tableData" :table-loading="tableLoading"
          :option="tableOption" :permission="permissionList" @search-change="searchChange"
          @refresh-change="refreshChange" @size-change="sizeChange" @current-change="currentChange"
          @row-del="handleDelete" @row-update="update" @row-save="create" :cell-style="cellStyle">

      <template slot="menu" slot-scope="scope">
            <el-button type="text" v-if="permissionList.delBtn" size="small" icon="el-icon-delete"
              @click="handleDelete(scope.row, scope.index)">
              删除
            </el-button>
            <el-dropdown size="mini" @command="handleCommand" placement="bottom">
              <el-button type="text" size="small" class="Morefeatures">更多</el-button>
              <el-dropdown-menu slot="dropdown" v-show="true" class="MoreFeatures_item">
                <el-dropdown-item :command="beforeHandleCommand(scope,'分配管理员')">分配管理员</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </template>

这里我们需要点击分配管理员时,拿到scope的值,那问题来了,怎么样才能拿到呢,查看官方文档发现, 这里只能拿到command

 <el-dropdown size="mini" @command="handleCommand(scope)" placement="bottom">
              <el-button type="text" size="small" class="Morefeatures">更多</el-button>
              <el-dropdown-menu slot="dropdown" v-show="true" class="MoreFeatures_item">
                <el-dropdown-item :command="beforeHandleCommand(scope,'分配管理员')">分配管理员</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>

这样写的话,可以拿到scope的值,但只能传递一个参,我们就不能通过command来判断点击的是哪一个按钮来,虽然我这里只有一个按钮,但功能还是需要考虑全面的。

 beforeHandleCommand(command) {
        return {
          'scope': scope,
          'command': command
        }
      },

这样写我们可以获得一个command的对象,里面存放着scope和command的值


  handleCommand(command) {
        const { scope } = command
        switch (command.command) {
          case "分配管理员":
            this.manageForm = scope.row
            this.isHandleManage = true
            this.selectParams.deptId = scope.row.deptId
            this.$refs.selectUser.showSelectUser()
            break;
        }
      },

无敌

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值